1

Im having problems to convert æ, ø, and å into ae, oe and aa.

I am trying to make a seo friendly url with this function, but it just removes the æøå signs.

My function is:

function seo_friendly_url($string, $cid) {
    //Unwanted:  {UPPERCASE} ; / ? : @ & = + $ , . ! ~ * ' ( )
    $string = strtolower($string);
    //Convert ÆØÅ
    $string = str_replace(chr(230), 'ae', $string); 
    $string = str_replace(chr(248), 'oe', $string); 
    $string = str_replace(chr(229), 'aa', $string); 
    //Strip any unwanted characters
    $string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
    //Clean multiple dashes or whitespaces
    $string = preg_replace("/[\s-]+/", " ", $string);
    //Convert whitespaces and underscore to dash
    $string = preg_replace("/[\s_]/", "-", $string);
    return $string;
}

Does anyone got any ideas on how to solve this issue. I have tried many difference things found around the web, but nothing seems to be working.

Jackie Honson
  • 1,419
  • 3
  • 13
  • 12

1 Answers1

1

Take a look at the comments on this man page: http://php.net/manual/en/function.urlencode.php

Perhaps something like:

function seo_friendly_url($url) {
    $url = strtolower($url);
    $url=str_replace('æ','ae',$url);
    $url=str_replace('ø','oe',$url);
    $url=str_replace('å','aa',$url);    
    return urlencode($url);
}

would do it?

Iesus Sonesson
  • 854
  • 6
  • 12