Created
April 21, 2012 09:18
-
-
Save mazhar266/fc06780fa2efe46fd2cb to your computer and use it in GitHub Desktop.
SEO style URL making (removing unsupported)
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 | |
function generateSlug($phrase, $maxLength) | |
{ | |
$result = strtolower($phrase); | |
$result = preg_replace("/[^a-z0-9\s-]/", "", $result); | |
$result = trim(preg_replace("/[\s-]+/", " ", $result)); | |
$result = trim(substr($result, 0, $maxLength)); | |
$result = preg_replace("/\s/", "-", $result); | |
return $result; | |
} | |
$title = "A bunch of ()/*++\'#@$&*^!% invalid URL characters "; | |
echo(generateSlug($title)); | |
// outputs | |
a-bunch-of-invalid-url-characters | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment