Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP URL解码不';我的情况不行_Php - Fatal编程技术网

PHP URL解码不';我的情况不行

PHP URL解码不';我的情况不行,php,Php,我的PHP echo';}> 输出(DOM) 我错过什么了吗 听起来您实际上不需要使用urldecode(),因为$item一开始并不是百分数编码的。您应该使用htmlspecialchars,以防它包含需要编码以在HTML中使用的字符 另外,您不应该将“放在url(…)中。第一个引号与style=“开头的引号匹配,因此它结束了该值 <div class="coverImg" style="background=url(" https:="" serembangirl.files.

我的PHP

echo';}>
输出(DOM)



我错过什么了吗

听起来您实际上不需要使用
urldecode()
,因为
$item
一开始并不是百分数编码的。您应该使用
htmlspecialchars
,以防它包含需要编码以在HTML中使用的字符

另外,您不应该将
放在
url(…)
中。第一个引号与
style=“
开头的引号匹配,因此它结束了该值

 <div class="coverImg" style="background=url(" https:="" serembangirl.files.wordpress.com="" 2014="" 11="" 20141005-071447.jpg?w="300&amp;h=400&quot;)" no-repeat="" center="" center"=""><a href="https://serembangirl.wordpress.com/2014/11/14/sometimes-i-forget/">
echo';}>

我猜URL是正确的,问题在于
&
添加第二个参数,表示为
&
因此您可以使用
html\u entity\u decode
修复此问题:

echo '<div class="coverImg" style="background=url('. htmlspecialchars($item) . ') no-repeat center center">'; } ?>
echo';}>
或者,您可以将这两种功能结合使用:

echo '<div class="coverImg" style="background=url("'. html_entity_decode($item) . '") no-repeat center center">'; } ?>
echo';}>

$item
的值是多少?你确定它是URL编码的,所以需要解码吗?@Barmar我不确定,$item只是一个普通的URL,像abc.com/something.jpgDon那样,你不想
urlencode
?创建URL的方法不对…显示完整的php代码可以转储$item的值以便我们查看它包含的内容吗?它仍然存在相同的问题听起来像
$item
实际上并不像您认为的那样包含URL。
echo '<div class="coverImg" style="background=url("'. html_entity_decode($item) . '") no-repeat center center">'; } ?>
echo '<div class="coverImg" style="background=url("'. urldecode(html_entity_decode($item)) . '") no-repeat center center">'; } ?>