这部分 PHP 有什么问题


What is wrong with this bit of PHP?

可能的重复项:
如何选择以带有 IF 语句的"<img"开头的行>

我正在尝试将"/images"添加到行的开头,text_image其中的文本以 img 开头。它给了我一个错误。

while($row = mysql_fetch_array( $result3 )) {
    echo "<div class='entry'>";
    $images = (substr($row['text_image']), 0, 3) == 'img') ? "/images" : "";
    echo $images . $row['text_image'];
    echo "</div>";
}

你有一个额外的括号。尝试:

$images = (substr($row['text_image'], 0, 3) == 'img') ? "/images" : "";
while($row = mysql_fetch_array( $result3 )) {
echo "<div class='entry'>";
$images = (
             substr($row['text_image'], 0, 3)
             == 'img') ? "/images" : "";
echo $images . $row['text_image'];
echo "</div>";
}