note 54635 deleted from function.strtr by danbrown
| From: | danbrown@php.net | Date: | Thu, 04 Mar 2010 18:21:58 +0000 |
| Subject: | note 54635 deleted from function.strtr by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-166677@lists.php.net to get a copy of this message | ||
Note Submitter: ru dot dy at gmx dot net
----
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;
}
?>