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.

example

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

Popular posts from this blog

How to show in django cms breadcrumbs full path? -

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -