在PHP中隐藏图像


Hide image in PHP

我有这个页面,显示一个图像占位符,即使使用以下PHP。看起来图片不应该使用<>"0"

显示http://westerndesignconference.com/intheloop/

<?php if ($row_rsGallery['artistPhoto']<>"0"){ ?>
<img src="../img/artists/<?php echo $row_rsGallery['artistPhoto']; ?>" width="100%" />
<?php } 
?>
<?php if ($row_rsGallery['artistPhoto2']<>"0"){ ?>
<img src="../img/artists/<?php echo $row_rsGallery['artistPhoto2']; ?>" width="100%" />
<?php } 
?>

var_dump('mystring' <> "0");

var_dump(null <> "0");

var_dump("" <> "0");

将求值为true。

另外,var_dump('mystring' == 0);也将求值为真。

你想要的是

if(false === empty($row_rsGallery['artistPhoto'])) {
}

这将确保$row_rsGallery['artistPhoto']的设置不会抛出索引未找到错误,并且包含除false或0以外的值。