我使用这个循环从文章中提取图像,将其放入图像库..所以我想 超出或忽略var $图像,如果不包含图像..换句话说,我不需要打印$ image或在画廊中留下空白空间..谢谢帮助
<?php
$count = 0;
// loop through and display format
foreach($articles as $article):
// stripes the table by adding a class to every other row
$class = ( ($count % 2) ? " class='altrow'": '' );
$regex = '/src="(.*?)"/';
preg_match_all($regex, $article['Article']['content'], $matches);
$matches = $matches[1];
foreach($matches as &$match)
$match = substr($match, strrpos($match, '/') + 1);
$image =(implode($matches ));
?>
<li> <?php
if(isset($image) && $image != ""){
e( $html->link( $html->image(image ,array('height'=>'75px', 'width'=>'75px')),array('action' => 'view', $article['Article']['id']),array('escape' => false)));
}else{
/// What is supposed to put here ///
}
?></li>
<?php endforeach; ?>
答案 0 :(得分:1)
您需要if语句来检查图像是否为空。如果是,请使用此处描述和演示的continue语句:http://php.net/manual/en/control-structures.continue.php
继续关键字将跳转到下一个迭代。