I'm currently retrieving data from my database. I receive an array that contains a 'title' index with an UTF8 encoded value. What I'd like is to use this value as the name of the file in which something will be saved, so I'm doing this:
file_put_contents($filename, $content);
Where $filename is
'-' . $category['root'] . '-articles-' . $category['id'] . '-' . $this->Urlize($category['category'])
Here is the code of "Urlize" :
private function Urlize($value)
{
if ($value != null && trim($value) != '')
{
$value = preg_replace('/([\[\(].*[\]\)])/i', '', $value);
$value = preg_replace('/[\s]/i', '-', $value);
$value = preg_replace('/[,!?.;:\"\'&+\/]/i', '-', $value);
$value = preg_replace('/[-]+/i', '-', $value);
$value = preg_replace('/(^-)/i', '', $value);
$value = preg_replace('/-$/i', '', $value);
$value = preg_replace('/[éèê]/i', 'e', $value);
$value = preg_replace('/[âà]/i', 'a', $value);
$value = preg_replace('/[öô]/i', 'o', $value);
$value = preg_replace('/[ûùü]/i', 'u', $value);
$value = preg_replace('/[îïíì]/i', 'i', $value);
$value = preg_replace('/[#]/i', 'sharp', $value);
$value = preg_replace('/[<>]/i', '-', $value);
if ($value[strlen($value) - 1] == '-')
{
$value = substr($value, 0, strlen($value) - 1);
}
}
return strtolower($value);
}
My issue is that for the title "Théorie générale", I get "theeorie-geeneerale", so "e" are doubled. I guess it is something related to the charset by I cannot find a good way to avoid it. Of course, I'd like to have "theorie-generale".
Thanks