php - Regular expression change the text, when it shouldnt -
this strange , cant find similar on internet.
i got table of strings in greek characters contains alot of special chars, wanted remove 'em.
function clean($string) { $string = preg_replace('/([$@!\?!\+\#\%\^\*\[\]\<\>\;\:\'\"\`\~\,\?\_\=\«\»])+/', ' ' ,$string); $string = preg_replace('/\s+/', ' ',$string); return $string; } $prok=clean($row['name']); echo $row['name'].'-'.$prok;
this working ok except when character Π
inside string. if Π
replace questionmark.
does have idea problem ??
you can try using mb_ereg_replace
support multibyte:
function clean($string) { $string = mb_ereg_replace('/([$@!\?!\+\#\%\^\*\[\]\<\>\;\:\'\"\`\~\,\?\_\=\«\»])+/', ' ' ,$string); $string = mb_ereg_replace('/\s+/', ' ',$string); return $string; } $prok=clean($row['name']); echo $row['name'].'-'.$prok;
or use /u
modifier unicode strings:
function clean($string) { $string = preg_replace('/([$@!\?!\+\#\%\^\*\[\]\<\>\;\:\'\"\`\~\,\?\_\=\«\»])+/u', ' ' ,$string); $string = preg_replace('/\s+/u', ' ',$string); return $string; } $prok=clean($row['name']); echo $row['name'].'-'.$prok;
Comments
Post a Comment