如何在php中包含变量值作为url的一部分
i、 将图像的url从表存储到变量imagefilename 现在,我希望使用该文件名并使用命令从其位置获取图像如何在php中包含变量值作为url的一部分,php,Php,i、 将图像的url从表存储到变量imagefilename 现在,我希望使用该文件名并使用命令从其位置获取图像 $imagefilename=$row['uimage']; echo'; 但是它没有考虑将“$imagefilename”作为url的一部分。有人能告诉我如何做到这一点吗?谢谢 使用如下单引号追加php变量: echo '<a href="update/update.php"><img id="unregistered" src="php/custome
$imagefilename=$row['uimage'];
echo';
但是它没有考虑将“$imagefilename”作为url的一部分。有人能告诉我如何做到这一点吗?谢谢 使用如下单引号追加php变量:
echo '<a href="update/update.php"><img id="unregistered" src="php/customer/customer_images/{$imagefilename}"/></a>';
echo';
试试这个
echo '<a href="update/update.php"><img id="unregistered" src="php/customer/customer_images/'.$imagefilename.'/></a>';
这里是一个答案中的所有注释:
<?php
$imagefilename = "file1.jpg";
echo '<a href="update/update.php"><img id="unregistered" src="php/customer/customer_images/'.$imagefilename.'/></a>';
echo "\n";
echo "OR";
echo "\n";
$imagefilename = "php/customer/customer_images/file1.jpg";
echo "https://localhost/folderName/update/update.php?$imagefilename";
?>
您需要使用
“
而不是”
或者像这样编写echo'sometext.$var.'someothertext';
根据具体情况,您可能也只能将变量注入到实际的HTML中:
我尝试了您的代码,但在我的数据库中有一个小错误”“存储的值仅为”IMG-20140414-WA0000.jpg“但是它添加了/%3E%3C/a%3E%3Ca%20href=extra i dono它从哪里来?你能帮我一下吗?urldecode()
source:是的,正如@Spirit所建议的。试试看它会吗work@AravindBhatK请告诉我如何在src double quotesTry中包含urldecode(),如下所示:echo“”;
//Your image url
$var = 'my%20text';
// echo with ' and urldecode
echo 'sometext '.urldecode($var).' someothertext';
//lambda function with urldecode
$myfunc = function($text) {
echo urldecode($text);
};
// working echo with {} (needs lambda function)
echo "somtext{$myfunc($var)}";