被 HTML 实体替换的字符重新出现
我在执行简单的 str_replace
时遇到问题。
我正在尝试从字符串中删除所有逗号,这确实有效。但是当我尝试再次更改字符串时,逗号以某种方式重新出现。我重构了我的代码以确保这不是我造成的。
无论如何,这是我的代码。有人能发现错误吗?
$delim=remDelim(fgets($fo));
# echo 'before : '.htmlspecialchars($delim);
$delime =str_replace(",",",",$delim);
echo 'after : '.htmlspecialchars($delime);
$delimed = str_replace("<","",$delime);
echo $delimed.'<br />';
example output:
Jose, jr to Jose, jr to Jose, jr
就像我的字符串没有被转换一样。我想说,很可能是我把名字搞混了,用第一个字符串来制作最后一个字符串。但可惜我发现事实并非如此。
I am having trouble doing a simple str_replace
.
I am trying to remove all comma's from a string, which does work. But when I try to alter the string again, the commas reappear somehow. I refactored my code to ensure I didn't cause this.
Anyways here is my code. Can anybody spot a bug?
$delim=remDelim(fgets($fo));
# echo 'before : '.htmlspecialchars($delim);
$delime =str_replace(",",",",$delim);
echo 'after : '.htmlspecialchars($delime);
$delimed = str_replace("<","",$delime);
echo $delimed.'<br />';
example output:
Jose, jr to Jose, jr to Jose, jr
Its like my string is being unconverted somehow. I would say that it was most likely I got the names mixed up and used the first string to craft the last. But alas I can see that is not the case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在浏览器中查看此内容,请注意,浏览器将将字符实体呈现为实际字符,而不是实体文本。强制浏览器进入纯文本模式 (
header('Content-type: text/plain');
),或查看页面的源代码(例如 ctrl-u 在火狐浏览器中)If you're viewing this in a browser, note that the browser WILL render the character entities as the actual character, not the entity text. Either force the browser into plain-text mode (
header('Content-type: text/plain');
), or view the page's source (e.g. ctrl-u in firefox)