how to strip punctuation in php

后端 未结 6 1502
长发绾君心
长发绾君心 2021-02-01 22:45

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

6条回答
  •  天命终不由人
    2021-02-01 23:23

    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);
    

提交回复
热议问题