[eluser]manilodisan[/eluser]
I'm using the following function to replace non alpha numeric characters for seo url's:
Code: preg_replace ( '/[^a-zA-Z0-9]/', '_', $string );
It works just fine but when someone uses another language like this polish example:
it removes the accented letters and everything else. I've tried a lot of string conversions and nothing works. How do I do to keep those letters intact?
I need something general as my clients are from all over the world...something that would transform them back to the original state and only after that display them...
Any ideas?
[eluser]Benjamin David[/eluser]
Hi, I had a similar issues using the url helper function called "url_title". I extended the function that way :
Code: function url_title($str, $separator = 'dash')
{
if ($separator == 'dash')
{
$search = '_';
$replace = '-';
}
else
{
$search = '-';
$replace = '_';
}
/* debut modif */
$caracteres_speciaux = array(
"¥" => "Y", "µ" => "u", "À" => "A", "Á" => "A", "Â" => "A", "Ã" => "A", "Ä" => "A", "Å" => "A", "Æ" => "A", "Ç" => "C", "È" => "E", "É" => "E", "Ê" => "E", "Ë" => "E", "Ì" => "I", "Í" => "I", "Î" => "I", "Ï" => "I", "Ð" => "D", "Ñ" => "N", "Ò" => "O", "Ó" => "O", "Ô" => "O", "Õ" => "O", "Ö" => "O", "Ø" => "O", "Ù" => "U", "Ú" => "U", "Û" => "U", "Ü" => "U", "Ý" => "Y", "ß" => "s", "à" => "a", "á" => "a", "â" => "a", "ã" => "a", "ä" => "a", "å" => "a", "æ" => "a", "ç" => "c", "è" => "e", "é" => "e", "ê" => "e", "ë" => "e", "ì" => "i", "í" => "i", "î" => "i", "ï" => "i", "ð" => "o", "ñ" => "n", "ò" => "o", "ó" => "o", "ô" => "o", "õ" => "o", "ö" => "o", "ø" => "o", "ù" => "u", "ú" => "u", "û" => "u", "ü" => "u", "ý" => "y", "ÿ" => "y", "€" => "e");
$str = strtr($str, $caracteres_speciaux);
/* fin modif */
$trans = array(
$search => $replace,
"\s+" => $replace,
"[^a-z0-9".$replace."]" => '',
$replace."+" => $replace,
$replace."$" => '',
"^".$replace => ''
);
$str = strip_tags(strtolower($str));
foreach ($trans as $key => $val)
{
$str = preg_replace("#".$key."#", $val, $str);
}
return trim(stripslashes($str));
}
I don't know if it has already be done the last release but it would be nice if Code Igniter could support it natively
[eluser]xwero[/eluser]
You can extend the helpers now. In the application/helpers directory you add a file my_url_helper.php with that function in it and do
Code: $this->load->helper('url')
To use your custom url_title function.
[eluser]Benjamin David[/eluser]
I don't know if you were replying to me but I meant that it would be cool if Code Igniter's URL Helper could support special characters and accents natively.
Thanks btw !
[eluser]xwero[/eluser]
Yes it was a reply to you, Benjamin David  CI isn't a fully internationalized framework as there are quite a few hardcoded English strings. But i would love to see it more internationalized too.
[eluser]Elliot Haughin[/eluser]
Yeah, this would be fantastic... I've had a few problems in the past with tags...
Users would put in their native (often spanish) tag names, and the urls for them would obviously break!
|