PHP preg_replace_callback with unicode
| From: | Jimmy Chen | Date: | Fri, 30 Mar 2012 18:05:04 +0000 |
| Subject: | PHP preg_replace_callback with unicode | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-317378@lists.php.net to get a copy of this message | ||
I wrote a simple script below to simulate my problem.
Both my string and pattern contain unicode characters.
Basically, if I run it from command line (php -f test.php), it prints
"match" as expected.
But if I run it through web server (apache, http://localhost/test.php), it
prints "no match".
I am using PHP 5.3.
I am sure both use the same php.ini.
Any idea why it behaves differently?
How do I make it work through web server?
Thanks
-----
<?php
function myCallback($matches) {
return $matches[0]; //do nothing, test only
}
$value = 'aaa äää';
$pattern = '/(\bäää)/u';
$value = preg_replace_callback($pattern, 'myCallback', $value, -1, $count);
if ($count > 0) {
echo "match";
} else {
echo 'no match';
}
?>