Skip to content

Instantly share code, notes, and snippets.

@zigo928
Last active August 3, 2018 02:02
Show Gist options
  • Save zigo928/d057639afb2118cf788ff9a7f64a548a to your computer and use it in GitHub Desktop.
Save zigo928/d057639afb2118cf788ff9a7f64a548a to your computer and use it in GitHub Desktop.
php正则,删除字符串中的中英文标点符号
<?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