Created
February 29, 2016 23:10
-
-
Save webmechanicx/6fc2e04f59af46c7c7d7 to your computer and use it in GitHub Desktop.
To covert a string to SEO friendly Slug-URL
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 | |
/* Sluggify - Simple Logic to turn a string to slug url | |
* To covert a string to SEO friendly | |
*/ | |
$title = "To covert a string to SEO friendly" | |
$slugs = preg_replace('/\%/',' percentage',$title); | |
$slugs = preg_replace('/\@/',' at ',$slugs); | |
$slugs = preg_replace('/\&/',' and ',$slugs); | |
$slugs = preg_replace('/\s[\s]+/','-',$slugs); // Strip off multiple spaces | |
$slugs = preg_replace('/[\s\W]+/','-',$slugs); // Strip off spaces and non-alpha-numeric | |
$slugs = preg_replace('/^[\-]+/','',$slugs); // Strip off the starting hyphens | |
$slugs = preg_replace('/[\-]+$/','',$slugs); // Strip off the ending hyphens | |
$slugs = strtolower($slugs); | |
echo $slugs; | |
//output: this-is-the-string-to-be-made-seo-friendly | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment