Results 1 to 6 of 6

Thread: str_replace not working - please help

  1. #1
    Join Date
    May 2006

    str_replace not working - please help

    Hi I am trying to ensure my output formats nicely
    so I am wanting to replace the /n with <br>.

    But it doesn't seem to be working

    Here is my code:

    PHP Code:
    $desc_lng = str_replace( "\n", '<br>', $desc_lng );

    <div style='position:absolute;left:420px; top:<?php  echo "$desc_top"?>;'>
    <P><?php  echo "$desc_lng"?>
    Have I done something wrong ?

    The output can be veiwed live on:


    Select the 6th advert down from top,
    with the heading "3 bedroomed house in New Southgate."

    You see what I mean - it is still full of /n/n 's ???

  2. #2
    Join Date
    Jul 2005

  3. #3
    Join Date
    Aug 2004
    I don't think it's a problem with the specific code you're using to remove newlines. Rather, the problem is that for some reason you have actual back-slashes followed by "n" characters in the text, not newline characters. (It's as if the text were defined as $text = 'first line\\nsecond line'; rather than $text = "first line\nsecond line";)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation


  4. #4
    Join Date
    May 2006
    Well I must admit that it seems to occure when a copy/pate is done.
    The /n can not be seen in the form and only shows up after accepted into the db and then re-displyed.

    I used to use nl2br() before input to db but read a few threads that said it wasn't necassary - just change the display.

    Now, the point is how do I change these this to <br> ?

    I am going to try this:

    $desc_lng = str_replace( "\\n", '<br>', $desc_lng );

    OR should I be doing something else ??

  5. #5
    Join Date
    May 2006
    Well that did the trick

    Should I have both, just to make sure ?

    PHP Code:
    $desc_lng str_replace"\\n"'<br>'$desc_lng ); 
    $desc_lng str_replace"\n"'<br>'$desc_lng ); 
    and is this the best way round ?

    Thanks for your comments as it has helped me sort it out

  6. #6
    Join Date
    Nov 2006
    Just have the top one

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles