Created
May 24, 2018 10:47
-
-
Save lcosta/b1a0e03c34c6af9a65eac7c1153062c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* prepares a string optimized for SEO | |
* @param string $sString | |
* @return string $sString SEO optimized string | |
*/ | |
function seofy ($sString = '') | |
{ | |
$sString = preg_replace ('/[^\pL\d_]+/u', '-', $sString); | |
$sString = trim ($sString, "-"); | |
$sString = iconv ('utf-8', "us-ascii//TRANSLIT", $sString); | |
$sString = strtolower ($sString); | |
$sString = preg_replace ('/[^-a-z0-9_]+/', '', $sString); | |
return $sString; | |
} | |
echo seofy('Straßenfest in München'); // => strassenfest-in-muenchen | |
echo seofy('José Ignacio López de Arriortúa'); // => jose-ignacio-lopez-de-arriortua |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment