note 54635 added to function.strtr

From: Date: Sun, 10 Jul 2005 22:53:44 +0000
Subject: note 54635 added to function.strtr
Groups: php.notes 
Request: Send a blank email to php-notes+get-91751@lists.php.net to get a copy of this message
The function 'getWriteString' for parsing URLs below is very useful, but it has a little bug. PHP strtolower does not recognize capitalized accented characters. The result is that they are replaced with '-'. To correct this, change the first line in the function from: <?php $string = htmlentities(strtolower($string)); ?> into: <?php $string = strtolower(htmlentities($sString)); ?> Theres another Problem with search-engines, regarding german keywords with umlaute. Searchengines such as Google replace german umlaute with a following 'e'. Replacing the umlaute in words just with their unaccented characters gives the word another or no sense. The result of this is that the contained keyword in the url is incorrect and brings minor advantage for the pagerank of the site. At last, this did it for me: <?php function getRewriteString($sString) { $string = strtolower( htmlentities( strtr($sString, array("Ä"=>"Ae", "Ü"=>"Ue", "Ö"=>"Oe", "ä"=>"ae", "ü"=>"ue", "ö"=>"oe")) ) ); $string = preg_replace("/&(.)(acute|cedil|circ|ring|tilde|uml);/", "$1", $string); $string = preg_replace("/([^a-z0-9]+)/", "-", html_entity_decode($string)); $string = trim($string, "-"); return $string; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.strtr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54635 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54635&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54635&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54635&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54635&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54635&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54635&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54635&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91751) next »