note 81123 rejected from function.mb-regex-encoding by nlopess

From: Date: Thu, 14 Feb 2008 20:16:20 +0000
Subject: note 81123 rejected from function.mb-regex-encoding by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-136159@lists.php.net to get a copy of this message
Note Submitter: sangwal at mailinfinity dot com ---- The function mb_eregi_replace does not seem to understand that Polish letters Ń and ń are same letter except for the difference of case. Similar is the case with Ł, Ą, Ó, Ę etc. <?php function clean_text($str, $pattern = "[^ a-ząęłńóżź]") { // there is some problem with Ń. don't know what mb_regex_encoding('utf-8'); mb_internal_encoding("UTF-8"); return mb_eregi_replace($pattern, "", $str); } $str = "SUŃIŁ sąńgwĄł this SUŃÓŻŹĆIL contains also a-z ą ę ł ń ó ż ź + 012334338 / + \" {} sun3il"; print clean_text($str); ?> Its output is:(html is added for clarity sake that utf-8 was in effect) <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Title</title> </head> SUI sąńgwł this SUIL contains also az ą ę ł ń ó ż ź sunil -- end of output -- As is obious from the code, I wanted to retain only Polish letters in the string and get rid of all others whatever. Does anybody know if it can be done with one regex-replace? Thanks.

« previous php.notes (#136159) next »