将Classic ASP if语句转换为PHP

时间:2014-04-01 03:23:21

标签: php asp-classic

我是php的新手,想知道是否有人可以帮助我将经典的asp if语句转换为php:

<img src="<%If rsRecordset.Fields.Item("image1").Value <> "" then response.write
(replace(rsRecordset.Fields.Item("image1").Value,".jpg","_small.jpg"))Else response.write
("images/NoPic.jpg")End if%>" width="50" height="40" border="0">

php line就像这样:

<img src="<?php echo $row_rsAdminMenu['image1']; ?>">

非常感谢任何帮助

1 个答案:

答案 0 :(得分:2)

<?php
if ($row_rsAdminMenu['image1']) {
    $src = $row_rsAdminMenu['image1'];
    $src = str_replace('.jpg', '_small.jpg', $src);
} else {
    $src = 'images/NoPic.jpg';
}
echo '<img src="' . htmlspecialchars($src, ENT_COMPAT, 'UTF-8') . '" />';