How can I strip punctuation except for these characters . = $ ' - € %
Here's a neat way to do it:
preg_replace("#[[:punct:]]#", "", $target);
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With