I am trying to create a function which accepts a string and converts it to seolink.
But it is looking very un professional
What will be the better way to optimize it? As the may be too many special characters.
The function lookis like
function seo_url($title) {
$titel = substr($title,0,160);
// Replace underscore with "-"
$titel = ereg_replace("_","-",$title);
// Replace space with "-"
$titel = ereg_replace(" ","-",$title);
// Replace special characters
$titel = Ereg_replace ("À", "A", $Titel);
$titel = ereg_replace("í", "i", $title);
$titel = ereg_replace("ó", "o", $title);
$titel = ereg_replace("ú", "u", $title);
$titel = ereg_replace("ñ", "n", $title);
$titel = ereg_replace("Ñ", "n", $title);
$titel = Strtolower (trim($title));
The only real way to make it look neater and smaller would be to use an or expression in your regex.
ie.
This as far as I have seen is the most common way to do this, and also faster I would hasten to guess.
You can download a character map or create your own for generating the regex string, then store the character map yourself for ease of editing also.
Then your code would be again much smaller and more robust, as it would load in an external character map, which maps each character to it’s counterpart.
another solution
Removing Accented UTF-8 Characters With PHP