如何用php从我的字符串中删除ascii字符x02?

时间:2012-06-06 13:27:32

标签: php regex ascii

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

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

但这不起作用。你有什么想法吗?

2 个答案:

答案 0 :(得分:4)

为什么要使用regexp?

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

答案 1 :(得分:1)

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

$keywords = preg_replace("/\x02/", '', $keywords);
相关问题