Last active
August 3, 2018 02:02
-
-
Save zigo928/d057639afb2118cf788ff9a7f64a548a to your computer and use it in GitHub Desktop.
php正则,删除字符串中的中英文标点符号
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$str = "!@#$%^&*(中'文:;﹑•中'文中'文().,<>|[]'\""; | |
//中文标点 | |
$char = "。、!?:;﹑•"…‘’“”〝〞∕¦‖— 〈〉﹞﹝「」‹›〖〗】【»«』『〕〔》《﹐¸﹕︰﹔!¡?¿﹖﹌﹏﹋'´ˊˋ―﹫︳︴¯_ ̄﹢﹦﹤‐˜﹟﹩﹠﹪﹡﹨﹍﹉﹎﹊ˇ︵︶︷︸︹︿﹀︺︽︾ˉ﹁﹂﹃﹄︻︼()"; | |
$pattern = array( | |
"/[[:punct:]]/i", //英文标点符号 | |
'/['.$char.']/u', //中文标点符号 | |
'/[ ]{2,}/' | |
); | |
$str = preg_replace($pattern, ' ', $str); | |
echo $str; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment