Issue
how to remove only this type of special chars ░▒▓█► from a string in php
I use this preg_replace('/[\x00-\x1F\x80-\xC0]/u', '',$string);
but i want to allow special char like à,â, ', ", for french language
Solution
You can use unicode character classes like \p{Latin}
for latin script, \p{Sc}
for currency, \p{P}
(or shorter \pP
) for punctuation characters:
$str = preg_replace('/[^0-9\p{Latin}\pP\p{Sc}@\s]+/u', '', $str);
You can find the different unicode character classes available in PCRE here. (search the sentence: "The following general category property codes are supported")
Answered By - Casimir et Hippolyte Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.