【问题标题】:PHP Clean Odd Characters from StringPHP 从字符串中清除奇数字符
【发布时间】:2014-07-11 21:34:16
【问题描述】:

我正在使用套接字接收一些信息 但根据客户端和操作系统,它会产生一些垃圾。

示例:接收“Hello”字符串

ÿþ^Xÿþ^_ÿþ ÿþ!ÿþ"ÿþ'ÿü^Eÿþ#Hello

这被存储在 $msg 变量中。我怎样才能从那些奇怪的字符中清除它? (字符因味精而异)。

提前致谢

【问题讨论】:

  • stackoverflow.com/questions/1401317/… 这可能对你有帮助
  • 您可以使用preg_replace('/[^\w\d]+/', '', strip_tags(html_entity_decode($str))) 获取字母和数字。
  • 我刚刚使用了 preg_replace('/[^\w\d\s]+/', '', strip_tags(html_entity_decode($str))) 并成功了。谢谢!!!

标签: php string str-replace resource-cleanup


【解决方案1】:

谢谢,成功了

preg_replace('/[^\w\d\s]+/', '', strip_tags(html_entity_decode($str)));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-30
    • 2015-07-15
    • 1970-01-01
    相关资源
    最近更新 更多