PHP regex-从字符串中删除特殊字符

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP regex-从字符串中删除特殊字符相关的知识,希望对你有一定的参考价值。

This will remove all non-ascii characters / special characters from a string.
  1. //Remove from a single line string
  2. $output = "Likening ‘not-critical’ with";
  3. $output = preg_replace('/[^(x20-x7F)]*/','', $output);
  4. echo $output;
  5.  
  6. //Remove from a multi-line string
  7. $output = "Likening ‘not-critical’ with Likening ‘not-critical’ with Likening ‘not-critical’ with. ' ! -.";
  8. $output = preg_replace('/[^(x20-x7F)x0Ax0D]*/','', $output);
  9. echo $output;

以上是关于PHP regex-从字符串中删除特殊字符的主要内容,如果未能解决你的问题,请参考以下文章