another str_replace prob with line breaks

Discussion in 'PHP' started by adeibiza, Nov 7, 2008.

  1. #1
    my fields have line breaks but when i use

    $xmlStr=str_replace("\n",'',$xmlStr);

    sod all happens - i know the replace works as i tested it with

    $xmlStr=str_replace("\n",'a',$xmlStr);

    i get

    a some text
    a more text
    a even more

    is there a function to "remove" a line break/character etc rather than "replace"
     
    adeibiza, Nov 7, 2008 IP
  2. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    so.. why exactly don't you replace with an empty string?
     
    keyaa, Nov 7, 2008 IP
  3. adeibiza

    adeibiza Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thats what i thought but nothing happens....
     
    adeibiza, Nov 7, 2008 IP
  4. adeibiza

    adeibiza Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    dontcha just love google - i had forgotten about carriage returns

    $xmlStr=str_replace("\n",'',$xmlStr);
    $xmlStr=str_replace("\r",'',$xmlStr);
     
    adeibiza, Nov 7, 2008 IP
  5. Bind

    Bind Peon

    Messages:
    70
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    why not just rtrim() it ?
     
    Bind, Nov 7, 2008 IP
  6. Shoro

    Shoro Peon

    Messages:
    143
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    rtrim() only removes line breaks at the end of the string. He clearly has to remove line breaks within the string content.
     
    Shoro, Nov 7, 2008 IP
  7. Bind

    Bind Peon

    Messages:
    70
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    i read the post wrong .. i assumed he was working with a single line.

    thanks for the heads up
     
    Bind, Nov 7, 2008 IP
  8. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Oh well of course, the dreaded Windows line break ;)
    $text = preg_replace("/(r|n)/", "", $text);
    PHP:
    Easiest way to get rid of them all I can think of.
     
    keyaa, Nov 7, 2008 IP