We are making our site an SEO-friendly site by following the pattern below:
http://OurWebsite.com/MyArticle/Math/Spain/Glaño
As you see, Glaño has a spelling character that search engines may not like it. On the other hand we cannot build up the last URL!
Any suggestions to maintain our current URL generation code to handle Spanish or French entries or we need to change our approach?
Try these functions:
function Slug($string, $slug = '-', $extra = null)
{
return strtolower(trim(preg_replace('~[^0-9a-z' . preg_quote($extra, '~') . ']+~i', $slug, Unaccent($string)), $slug));
}
function Unaccent($string)
{
return html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($string, ENT_QUOTES, 'UTF-8')), ENT_QUOTES, 'UTF-8');
}
And use it like this:
echo Slug('Iñtërnâtiônàlizætiøn of Glaño'); // internationalizaetion-of-glano
You can embed the Unaccent()
code into the Slug()
function if you wish to have only one function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With