Img不会使用PHP显示

时间:2015-09-20 13:40:04

标签: php html image

此代码的要点是使用post变量显示动物的图片n次。

问题是只为图像显示alt。

以下是整个代码: 给定URL:/index.php?animal=boxer&count=3

<?php
    $animal = $_GET['animal'];
    $count = $_GET['count'];

    $valid_animals = array("crow", "boxer", "rat");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Animoz</title>
</head>
<body>
<p>
    <?php if (in_array($animal, $valid_animals)): ?>
        <?php for ($j = 0; $j < $count; $j++): ?>
            <img src="images/<?=$animal?>.jpg" alt="<?=$animal?>">
        <?php endfor; ?>
    <?php else: ?>
        <p> I can't show you any <?=$animal?>s!!!!</p>
    <?php endif; ?>
</p>
</body>
</html>

我也尝试过:

<?php
    if (in_array($animal, $valid_animals))
    {
        for ($j = 0; $j < $count; $j++)
        {
            echo '<img src="'. $animal . '.jpg" alt="' . $animal . '">';
        }
    }
?>

它的HTML代码看起来很好:

<body>
     <p>
        <img src="images/boxer.jpg" alt="boxer">
        <img src="images/boxer.jpg" alt="boxer">
        <img src="images/boxer.jpg" alt="boxer">    
     </p>
</body>

正在使用的文件路径是正确的。

知道我在这里做错了什么?

0 个答案:

没有答案
相关问题