我想在 PHP 脚本中将图像分配给变量,以便我可以通过声明变量使图像在我想要的时候出现。
$FoodList = array_unique($FoodList);
if (!empty($FoodList)) {
foreach ($FoodList as $key => $value) {
// The variable would go here, so that image would appear
//next to each variable
echo "<li>" . $value . "<li>";
}
echo "</ul>";
}
要么你分配 $var = "img src="'your/pathto/image.ext'";
$var = "your/pathto/image.ext";
并在 HTML IMG 代码中回显它
第二种方法更可取
$FoodList = array_unique($FoodList);
if(!empty($FoodList)) {
foreach ($FoodList as $key => $value) {
//The variable would go here, so that image would appear
//next to each variable
$value = "<li>";
//Maybe you'll only display an image is a certain condition is met? If so, then...
if($condition == "parameter") {
$value .= "<img src='path/to/img' alt='img' />";
}
$value .= "</li>";
echo $value;
unset($value);
}
echo "</ul>";
}
$FoodList=array_unique($FoodList);
$img_path = 'images/example.jpg';
if(!empty($FoodList))
{
foreach ($FoodList as $key => $value)
{
echo "<img src='$img_path' />";
echo "<li>".$value."<li>";
}
echo "</ul>";
}
使用这个:
echo "<li><img src='path_of_image/".$value."'/><li>";
假设$value
具有图像的名称和图像扩展名。
<?php
$name="Adil";
echo $name;
$path="FB_IMG_1465102989930.jpg";
for($i=0;$i<44;$i++)
{
echo($i.'<br>') ;
if($i==10)
{
echo ".$path.";
echo "<img src ='".$path."'>";
}
}
?>
请在您的图像名称前插入一个空格:-例:-
$image_name="myphoto.jpg";
$image_path="./upload/ ".$image_name;
在这里,我在"./upload/(space)"
之后添加一个空格
将映像路径存储到 MySql 数据库中。
从您的 HTML 页面调用它为:-
<img src= '<?php echo $image_path;?>'width="200" height="200" alt=""/>