str_replace with åäö characters.

Discussion in 'PHP' started by skum, Mar 13, 2010.

  1. #1
    I'm simply trying to remove parts of strings, which is usually quite simple with str_replace. The problem is that some of the parts contain swedish characters and PHP just seems to ignore them

    Example:
    $string="<font size=4>tråkig</font>More text. ";
    $newstring=str_replace("<font size=4>tråkig</font>", "", $string);
    
    Code (markup):
    Doesn't work. However,
    $newstring=str_replace("<font size=4>", "", $string);
    Code (markup):
    removes the text as it's supposed to.

    I've tried to:
    • Use &aring; instead.
    • Just replacing "Ã¥" with "a"
    • Use chr(int)

    Any ideas of how I can replace the "Ã¥"? Should be very simple but something is not working.

    Thank you.
     
    skum, Mar 13, 2010 IP
  2. skum

    skum Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've found a solution, even though it's a bit confusing.
    $newstring=str_replace("&lt;font size=4&gt;tr&aring;kig.&lt;/font&gt;", "",htmlentities($string));
    $newstring=html_entity_decode($newstring);
    Code (markup):
     
    skum, Mar 13, 2010 IP
  3. miller23

    miller23 Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    maybe you should work with encoding to solve this problem
     
    miller23, Mar 17, 2010 IP
  4. skum

    skum Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It wasn't possible since the values where pulled from an external DB.
    But as I said, the solution above works.
     
    skum, Mar 18, 2010 IP