Reputation: 9
I have problem with preg_replace
. How to leave these symbols: . , ? ! ' " : ;
and remove others? This function used with Lithuanian letters and numbers. I have tried this code:
preg_replace('/[^\p{L}\p{N}\s !?,;:.-]/u', '', $value);
Upvotes: 0
Views: 79
Reputation: 451
You have to escape those characters that have a special meaning in regular expression in that case.
preg_replace ('/[^\.,?!\'":;\-]/', '' ,$value);
preg_quote can also be used:
$toKeep = preg_quote ('.,?!\'":;', '/');
preg_replace ('/[^' . $toKeep . ']/', '', $value);
Upvotes: 2