I have the following PHP test code:
header('Content-type: text/html; charset=utf-8'); $text = 'Développeur Web'; var_dump($text); $text = preg_replace('#[^\\pL\d]+#u', '-', $text); var_dump($text); $text = trim($text, '-'); var_dump($text); $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); var_dump($text); $text = strtolower($text); var_dump($text); $text = preg_replace('#[^-\w]+#', '', $text); var_dump($text);
On my local machine, it works as expected:
string(16) "Développeur Web" string(16) "Développeur-Web" string(16) "Développeur-Web" string(16) "D'eveloppeur-Web" string(16) "d'eveloppeur-web" string(15) "developpeur-web"
but on my real server it behaves strangely:
string 'Développeur Web' (length=16) string '-pp-' (length=4) string 'pp' (length=2) string 'pp' (length=2) string 'pp' (length=2) string 'pp' (length=2)
The local machine is Windows running PHP version 5.2.4, and the live server is CentOS, running PHP version 5.2.10, so they are not identical in any way, not the ideal that I know.
Has anyone experienced something like this and can point me in the right direction? I assume this is some kind of server or PHP configuration related to UTF-8 or locale.
Thank you very much in advance
linux php apache preg-replace utf-8
Peter Hough
source share