Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Rafael Fernandes_150844

[Resolvido] array

Recommended Posts

Galera, recebi um array aqui, que eu percebi que é parecido com aqueles que são inseridos no bd do wordpress, só que não sei trabalhar com eles, gostaria de uma explicação

 

<?
a:1:{i:0;a:23:{s:2:"id";i:3288692;s:5:"title";s:32:"Kayaking Tasmania's Leven Canyon";
s:11:"description";
s:162:"Lachie Carracher and Sean Bozkewycz paddling the committing Leven River Canyon, which contains two mandatory falls - a 20 footer followed directly by a 40 footer.";
s:3:"url";s:24:"http://vimeo.com/3288692";s:11:"upload_date";s:19:"2009-02-19 17:41:55";s:15:"thumbnail_small";s:48:"http://b.vimeocdn.com/ts/177/329/1773297_100.jpg";s:16:"thumbnail_medium";s:48:"http://b.vimeocdn.com/ts/177/329/1773297_200.jpg";s:15:"thumbnail_large";s:48:"http://b.vimeocdn.com/ts/177/329/1773297_640.jpg";s:7:"user_id";i:1291729;s:9:"user_name";s:7:"Feed It";s:8:"user_url";s:23:"http://vimeo.com/feedit";s:19:"user_portrait_small";s:42:"http://b.vimeocdn.com/ps/914/914904_30.jpg";s:20:"user_portrait_medium";s:42:"http://b.vimeocdn.com/ps/914/914904_75.jpg";s:19:"user_portrait_large";s:43:"http://b.vimeocdn.com/ps/914/914904_100.jpg";s:18:"user_portrait_huge";s:43:"http://b.vimeocdn.com/ps/914/914904_300.jpg";s:21:"stats_number_of_likes";i:2;s:21:"stats_number_of_plays";i:997;s:24:"stats_number_of_comments";i:0;s:8:"duration";i:240;s:5:"width";i:480;s:6:"height";i:270;s:4:"tags";s:135:"Tasmania, Whitewater, Whitewater Kayaking, Feed It, Huck, Creeking, Kayaking, waterfalls, waterfall, kayak, river, creek, gorge, canyon";s:13:"embed_privacy";s:8:"anywhere";}}

?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Esse tipo de formato de representação é realizado pela função serialize(). A função serialize server para representar um valor numa forma que é possível armazená-lo sem perder suas características.

 

Por exemplo, você não pode salvar diretamente um array em um banco de dados e obter o mesmo array do SGDB. Para essa funcionalidade, utiliza-se serialize.

 

Entretanto, serialize não funciona com objetos do tipo resource.

 

Utilize a função unserialize()

 

$teste = <<<TXT
a:1:{i:0;a:23:{s:2:"id";i:3288692;s:5:"title";s:32:"Kayaking Tasmania's Leven Canyon";s:11:"description";s:162:"Lachie Carracher and Sean Bozkewycz paddling the committing Leven River Canyon, which contains two mandatory falls - a 20 footer followed directly by a 40 footer.";s:3:"url";s:24:"http://vimeo.com/3288692";s:11:"upload_date";s:19:"2009-02-19 17:41:55";s:15:"thumbnail_small";s:48:"http://b.vimeocdn.com/ts/177/329/1773297_100.jpg";s:16:"thumbnail_medium";s:48:"http://b.vimeocdn.com/ts/177/329/1773297_200.jpg";s:15:"thumbnail_large";s:48:"http://b.vimeocdn.com/ts/177/329/1773297_640.jpg";s:7:"user_id";i:1291729;s:9:"user_name";s:7:"Feed It";s:8:"user_url";s:23:"http://vimeo.com/feedit";s:19:"user_portrait_small";s:42:"http://b.vimeocdn.com/ps/914/914904_30.jpg";s:20:"user_portrait_medium";s:42:"http://b.vimeocdn.com/ps/914/914904_75.jpg";s:19:"user_portrait_large";s:43:"http://b.vimeocdn.com/ps/914/914904_100.jpg";s:18:"user_portrait_huge";s:43:"http://b.vimeocdn.com/ps/914/914904_300.jpg";s:21:"stats_number_of_likes";i:2;s:21:"stats_number_of_plays";i:997;s:24:"stats_number_of_comments";i:0;s:8:"duration";i:240;s:5:"width";i:480;s:6:"height";i:270;s:4:"tags";s:135:"Tasmania, Whitewater, Whitewater Kayaking, Feed It, Huck, Creeking, Kayaking, waterfalls, waterfall, kayak, river, creek, gorge, canyon";s:13:"embed_privacy";s:8:"anywhere";}}'
TXT;

echo '<pre>';
var_dump(unserialize($teste));
echo '</pre>';

 

Saída:

array(1) {

[0]=>

array(23) {

["id"]=>

int(3288692)

["title"]=>

string(32) "Kayaking Tasmania's Leven Canyon"

["description"]=>

string(162) "Lachie Carracher and Sean Bozkewycz paddling the committing Leven River Canyon, which contains two mandatory falls - a 20 footer followed directly by a 40 footer."

["url"]=>

string(24) "

["upload_date"]=>

string(19) "2009-02-19 17:41:55"

["thumbnail_small"]=>

string(48) "http://b.vimeocdn.com/ts/177/329/1773297_100.jpg"

["thumbnail_medium"]=>

string(48) "http://b.vimeocdn.com/ts/177/329/1773297_200.jpg"

["thumbnail_large"]=>

string(48) "http://b.vimeocdn.com/ts/177/329/1773297_640.jpg"

["user_id"]=>

int(1291729)

["user_name"]=>

string(7) "Feed It"

["user_url"]=>

string(23) "http://vimeo.com/feedit"

["user_portrait_small"]=>

string(42) "http://b.vimeocdn.com/ps/914/914904_30.jpg"

["user_portrait_medium"]=>

string(42) "http://b.vimeocdn.com/ps/914/914904_75.jpg"

["user_portrait_large"]=>

string(43) "http://b.vimeocdn.com/ps/914/914904_100.jpg"

["user_portrait_huge"]=>

string(43) "http://b.vimeocdn.com/ps/914/914904_300.jpg"

["stats_number_of_likes"]=>

int(2)

["stats_number_of_plays"]=>

int(997)

["stats_number_of_comments"]=>

int(0)

["duration"]=>

int(240)

["width"]=>

int(480)

["height"]=>

int(270)

["tags"]=>

string(135) "Tasmania, Whitewater, Whitewater Kayaking, Feed It, Huck, Creeking, Kayaking, waterfalls, waterfall, kayak, river, creek, gorge, canyon"

["embed_privacy"]=>

string(8) "anywhere"

}

}

Compartilhar este post


Link para o post
Compartilhar em outros sites

Eu complementei a explicação do post #2 para maiores informações.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.