需要帮助更换和与 &;
我不知道为什么我无法将 &
替换为 &
这是我的字符串:/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
有什么建议吗?
更新
是的,它是 标记使用的图像网址的一部分。
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
我还测试了用 /Designers/batlak&selvig.jpg
替换 $brand['image']
>
I have no idea why I'm not able replace &
with &
This is my string: /Designers/batlak&selvig.jpg
.
This is what I've tried so far:
$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
Any suggestions?
update
Yes, it's a part of an image url used by the <img>
tag.urlencode
does not work - the image tag does not understand the format.
This is the error I get at W3C Validator:
Validation Output: 1 Error
Line 84, Column 104: & did not start a character reference.
(& probably should have been escaped as &.)
UPDATE 2
This is how I'm testing it:
<?php
$image = str_replace('&','&',$brand['image']);
echo $image;
?>
Output:/Designers/batlak&selvig.jpg
I've also tested replacing $brand['image']
with /Designers/batlak&selvig.jpg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Firebug 会“自动隐藏”HTML 实体。
因此,请运行并粘贴原始(查看源代码、复制、粘贴)结果:
我的猜测是:
问题显然是您的文件名中有一个&符号,这很棘手;)
Firebug does "auto-hide" HTML entities.
So please run and paste the raw (View Source, Copy, Paste) result:
My guess would be:
The problem is appearantly that you have an ampersand in your filename which is... tricky ;)
对我有用:
也许您将其放入 href 或 src 中,并在浏览器状态/位置栏中转义。如果你查看源代码,它会被正确转义。
Works for me:
Perhaps you are throwing this into an href or src where it is escaped in the browser status/location bar. If you look in the source code, it will be properly escaped.
对于 URL:
对于您的问题:
替换所有
'&'
而不替换任何现有的'&'
字符。For a URL:
For your question:
That replaces all
'&'
without replacing any existing'&'
characters.