str_replace ° to ° not working :(

Discussion in 'PHP' started by joezo, Apr 28, 2010.

  1. #1
    Now I had this working a few weeks ago but something must have changed and now it no longer works.
    Here's my code, if someone could help me out and spot any errors or give advice, that would be brilliant:) It just responds with the original string, nothing changed.
    $pos1[1] = str_replace("°","°",$pos1[1]);  
    echo $pos1[1];
    PHP:

     
    joezo, Apr 28, 2010 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That code works perfectly fine. be sure to check that $pos1[1] contains the ° for sure BEFORE the str_replace
     
    JAY6390, Apr 28, 2010 IP
  3. joezo

    joezo Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Really weird how it wouldn't work, I even tested that piece of code in a separate file and set the variable myself. $pos1[1] definitely contained it as I was displaying it beforehand so I could compare the result. Just wouldn't work when in the main file, ended up using htmlentities() which has worked fine, oddly.
     
    joezo, Apr 28, 2010 IP
  4. khajeya

    khajeya Member

    Messages:
    256
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #4
    please also try to use htmlspecialchars function :)
     
    khajeya, Apr 30, 2010 IP