To just answer your requirement .. here you go ..
function makeSeo($text, $limit=75)
{
// replace non letter or digits by -
$text = preg_replace('~[^\pLd]+~u', '-', $text);
// trim
$text = trim($text, '-');
// lowercase
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-w]+~', '', $text);
if(strlen($text) > 70) {
$text = substr($text, 0, 70);
}
if (empty($text))
{
//return 'n-a';
return time();
}
return $text;
}
You can add more filters to clean the url and may be you add some more stuff to get that url a unique.
Note: I am not saying that adding url to the database is the best way. You could achieve the same sort of functionality using other techniques, for example, mod_rewrite.
We specialize in SEO for helping medium to large businesses in Maryland City USA and convert high-quality, high-intent traffic into important business leads.
Higher Positions is a premier SEO company in Biloxi, and a Google Partner and SEO-Certified, with over 10 years of search engine marketing experience.