php如何去掉标点符号 [英] how to strip punctuation in php

查看:35
本文介绍了php如何去掉标点符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何去除标点符号,除了这些字符. = $ ' - %

How can I strip punctuation except for these characters . = $ ' - %

推荐答案

由于您需要匹配某些 Unicode 字符 (),因此使用正则表达式是明智的.模式 \p{P} 匹配任何已知的标点符号,并且断言将您想要的特殊字符排除在消失之外:

Since you need to match some Unicode characters () it would be sensible to use a regular expression. The pattern \p{P} matches any known punctuation, and the assertion excludes your desired special characters from vanishing:

 $text = preg_replace("/(?![.=$'€%-])\p{P}/u", "", $text);

这篇关于php如何去掉标点符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆