簡體   English   中英

如何在Wordpress,PHP,JavaScript上使用正則表達式從字符串(URL)中刪除特殊字符

[英]How to remove special characters from a string (URL) using regular expression on wordpress, php, javascript

我想從字符串中刪除特殊字符。 我用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特殊字符( U + FFFD )。 以下代碼將保留字母,數字,標點符號和空格,同時刪除所有其他Unicode字符:

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

查看正則表達式末尾的u修飾符。 您需要它,因為該字符串具有Unicode特殊字符。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM