【发布时间】:2019-06-06 18:49:10
【问题描述】:
我有这个代码:
$profile_image_url = str_replace(" ", "%20", 'https://www.example.com/images/cropped (1).jpg');
$output .= "style='background:url('https://www.example.com/images/" . $profile_image_url . "')no-repeat;'";
输出结果为:
style="background:url(" https: www.example.com images cropped (1).jpg')no-repeat;
如何修复这行代码以防止 URL 斜杠被删除?谢谢!
$output .= "style='background:url('https://www.example.com/images/" . $profile_image_url . "')no-repeat;'";
我试过用反斜杠转义最里面的单引号,但没有用 -->
$output .= "style='background:url(\'https://www.example.com/images/" . $profile_image_url . "\')no-repeat;'";
【问题讨论】:
-
“输出结果” - 中间的代码是什么?你如何回显/vardump
$output?无论如何,您在 js 中都会遇到单引号问题:style='background:url('https..第二个'需要转义。但这一切都取决于你如何将它输出到哪里。 -
它在结尾回显“echo $output;”
-
中间一定有什么,因为这里的单引号
style='back也变成了双引号。请参阅此小提琴:3v4l.org/b9e4C 您在此处显示的代码正在按您的预期工作。 -
只有问题顶部的 2 行会产生正确的输出。
标签: php escaping double-quotes single-quotes