我不知道为什么我不能用&替换&
这是我的字符串:/Designers/batlak&selvig.jpg。
这就是我迄今为止尝试过的:
$image = preg_replace("#(&(?!amp;))#U",'&',$brand['image']);
$image = str_replace('&','&',$brand['image']);
$image = htmlspecialchars($brand['image']);
$image = mysql_real_escape_string($brand['image']);
$image = urlencode($brand['image']); // This works, but image will not show
$image = rawurlencode($brand['image']); // This works, but image will not show有什么建议吗?
更新
是的,它是<img>标记使用的图像url的一部分。
urlencode不工作-图像标记不理解格式。
这是我在W3C验证器上遇到的错误:
Validation Output: 1 Error
Line 84, Column 104: & did not start a character reference.
(& probably should have been escaped as &.)更新2
我就是这样测试的:
<?php
$image = str_replace('&','&',$brand['image']);
echo $image;
?>输出:
/Designers/batlak&selvig.jpg
我还测试过用$brand['image']替换/Designers/batlak&selvig.jpg
发布于 2010-11-08 21:57:55
为我工作:
echo str_replace('&', '&', '/Designers/batlak&selvig.jpg');
// output:
Designers/batlak&selvig.jpg可能是将其放入href或src中,在浏览器状态/位置栏中转义。如果您查看源代码,它将正确转义。
发布于 2010-11-08 21:58:25
对于URL:
$image = urlencode($brand['image'])关于你的问题:
preg_replace('/&(?![A-Za-z0-9#]{1,7};)/','&',$brand['image']);它替换所有'&'而不替换任何现有的'&'字符。
发布于 2010-11-08 22:28:01
Firebug会自动隐藏HTML实体。
因此,请运行并粘贴原始(查看源、复制、粘贴)结果:
var_dump($brand['image']);
var_dump(urlencode($brand['image']));
var_dump(htmlspecialchars($brand['image']));我猜是:
$image = htmlspecialchars(urlencode($brand['image']));问题是你的文件名中有一个密码,就是.(棘手;)
https://stackoverflow.com/questions/4128415
复制相似问题