如何在json解码foreach中添加imagejudgement。如果最后有jpg,png,gif
,那么echo html_entity_decode($result->url)
,否则不是。谢谢。
foreach ($data->query->allimages as $result) {
echo '<img src="'.html_entity_decode($result->url).'" /><br/>';
}
答案 0 :(得分:1)
所以请试试这个:
foreach ($data->query->allimages as $result) {
$path = pathinfo($result->url);
if(!in_array($path['extension'], array('jpg','png','gif'))) continue;
echo '<img src="'.html_entity_decode($result->url).'" /><br/>'."\n";
}