【问题标题】:How can I remove the ascii character x02 from my string with php?如何使用 php 从我的字符串中删除 ascii 字符 x02?
【发布时间】:2012-06-06 13:27:31
【问题描述】:

我尝试了很多东西,但没有任何反应。由于 ascii 字符 x02(在 VIM 中为 '^B'),我生成的 xml 格式不正确。我已经尝试过以下行:

$keywords = preg_replace('/\x02/', '', $keywords);

但这行不通。你有什么想法吗?

【问题讨论】:

  • 尝试用双引号替换单引号"/\0x2/"

标签: php regex ascii


【解决方案1】:

为什么要使用正则表达式?

str_replace(chr(2),'',$keywords);

【讨论】:

  • 我从字符串替换开始,但它不起作用。现在我知道为什么了……我看错地方了……-.- 抱歉浪费您的时间,感谢您的快速回答!
【解决方案2】:

您必须使用" 来使用转义序列。将您的代码替换为:

$keywords = preg_replace("/\x02/", '', $keywords);

【讨论】:

    猜你喜欢
    • 2012-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-12
    • 1970-01-01
    • 2011-02-14
    相关资源
    最近更新 更多