<a href="'.$productLink.'" alt="'.$productName.'">
<img src="'.$productImg1URL.'" alt="'.$productName.' '.$productType.' ">
</a>
您好,img src 实际上位于不同的目录 /images
我知道这可能非常简单,但我已经花了一个小时在上面,什么也没做。该页面有效,但不显示目录。请帮助菜鸟。我把a href前面的<去掉,img src不能让页面显示
有两种方法可以做到这一点:
首先,在代码块之外:
<?php
// code here
?>
<a href="<?= $productLink ?>" alt="<?= $productName ?>">
<!-- or -->
<img src="<?echo $productImgURL; ?> alt="<?php echo $productName . ' ' . $productType ?>">
</a>
第一种形式称为短打开标记,必须在您的 php.ini 中启用,它几乎总是如此。
或者,如果您在代码块中执行此操作:
<?php
echo <<<END
<a href="$productLink" alt="$productName">
<img src="$productImgLURL" alt="$productName $productType">
</a>
END
这<<<END
是一个heredoc,我通常更喜欢在双引号内使用大字符串,这需要转义包含的双引号。
Job #1 when you have a problem with code that is generating HTML, is look at the output source and compare it with what you expect. I've had problems like this before and they usually vanished when I stopped thinking about the PHP code, and looked at the actual output.
What is the content of $productImg1URL - and if the images that it's referencing are in the URL starting /images/ - does that start $productImg1URL. If it's just the name of an image, but without the path - you have to put that into place.