Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在wordpress、php和javascript上使用正则表达式从字符串(URL)中删除特殊字符_Javascript_Php_Wordpress - Fatal编程技术网

如何在wordpress、php和javascript上使用正则表达式从字符串(URL)中删除特殊字符

如何在wordpress、php和javascript上使用正则表达式从字符串(URL)中删除特殊字符,javascript,php,wordpress,Javascript,Php,Wordpress,我想从字符串中删除特殊字符。我使用了esc_html(),htmlentities()等… 我无法得到结果。 我还使用了正则表达式,如下所示: $refine_re="My response to this article:�http://www.theaustralian.com.au/australian-it/it-business/eugene-kaspersky-queries-breach-rules/story-e6frganx-1226656443211" preg_repla

我想从字符串中删除特殊字符。我使用了
esc_html()
htmlentities()
等…
我无法得到结果。
我还使用了正则表达式,如下所示:

$refine_re="My response to this article:�http://www.theaustralian.com.au/australian-it/it-business/eugene-kaspersky-queries-breach-rules/story-e6frganx-1226656443211"

preg_replace("/&(?:[a-z0-9;]{2,8}|#[0-9;]{2,4})/i", '', $refine_re);

您试图删除的字符根本不是HTML实体。这是一个Unicode特殊字符()。以下代码将保留字母、数字、标点符号和空格,同时删除所有其他Unicode字符:

$refine_re = preg_replace("/[^[:alnum:][:punct:][:space:]]/u", "", $refine_re);
print($refine_re);

查看正则表达式末尾的
u
修饰符。您需要它,因为字符串有Unicode特殊字符。

首先,您需要用分号结束每个PHP语句。它的工作很好。但是我使用/I而不是/u。如果我使用\u,则不会显示文本。谢谢您节省了大量时间。