-
-
Save gentlyawesome/a2ebbd05fe06694f7e18 to your computer and use it in GitHub Desktop.
Convert title to seo friendly url
This file contains hidden or 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 | |
class SanitizeUrl { | |
public static function slug($string, $space="-") { | |
$string = utf8_encode($string); | |
if (function_exists('iconv')) { | |
$string = iconv('UTF-8', 'ASCII//TRANSLIT', $string); | |
} | |
$string = preg_replace("/[^a-zA-Z0-9 \-]/", "", $string); | |
$string = trim(preg_replace("/\\s+/", " ", $string)); | |
$string = strtolower($string); | |
$string = str_replace(" ", $space, $string); | |
return $string; | |
} | |
} | |
$title = 'Thi is a test string with some "strange" chars ò à ù...'; | |
echo SanitizeUrl::slug($title); | |
//this will output: | |
//thi-is-a-test-string-with-some-strange-chars-o-a-u |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment