php正则过滤替换标点符号
微wx笑 2022-06-07【编程语言】 1 0关键字: php 正则
php正则过滤替换标点符号
php正则过滤替换标点符号
function getEregWord($word, $type = '') { // Filter 英文标点符号 $word = preg_replace("/[[:punct:]]/i", $type, $word); // Filter 中文标点符号 mb_regex_encoding('utf-8'); $char = "。、!?:;﹑•"…‘’“”〝〞∕¦‖— 〈〉﹞﹝「」‹›〖〗】【»«』『〕〔》《﹐¸﹕︰﹔!¡?¿﹖﹌﹏﹋'´ˊˋ―﹫︳︴¯_ ̄﹢﹦﹤‐˜﹟﹩﹠﹪﹡﹨﹍﹉﹎﹊ˇ︵︶︷︸︹︿﹀︺︽︾ˉ﹁﹂﹃﹄︻︼()"; $word = mb_ereg_replace("[" . $char . "]", $type, $word, "UTF-8"); // Filter 连续空格 $word = preg_replace("/\s+/", $type, $word); if ($word) { $wordTmp = explode(',', $word); $word = $wordTmp ? implode(',', array_unique(array_filter($wordTmp))) : ''; } return $word; }
转自:https://blog.csdn.net/websites/article/details/115522442
本文为转载文章,版权归原作者所有,不代表本站立场和观点。