SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I'm pulling my hair out on this one

    My news script has a function that lets posts be nl2br()ed. But when I'm editing posts, they're nl2br()ed again.
    Problem is nl2br() seems to replaces \n with \n<br /> instead of just <br />.

    I've been trying some reverse thing lik eregi_replace('\n<br />','<br />', $post), but it doesn't work. Actually none of the replace methods where a newline is involved, has worked.

    So, how would I replace '\n<br />' with just '\n' ?
    [blogger: zengun] [blogware contributor: wordpress]

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try escaping the escape character. Something like:

    str_replace('\\n<br />','<br />', $post)

  3. #3
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Didn't work either
    [blogger: zengun] [blogware contributor: wordpress]

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK - another brain wave - enclose the string with the newline char in double quotes so that php parses it as the newline marker and not literally as slash+n

    str_replace("\n<br />",'<br />', $post)

    Just thinking out aloud, worth a try.

    BTW, contact me about your blogathon. Has that happened yet?

  5. #5
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aaaaaaah, so that's where the difference between simple and double quotes is !

    Anyway, I found the solution by looking at PHP's source code. I was wrong: nl2br replaces \n with <br>\n and not \n<br>, so I did a simple str_replace("<br />\n","\n",$post) and it works now
    [blogger: zengun] [blogware contributor: wordpress]

  6. #6
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Shin Ma
    Aaaaaaah, so that's where the difference between simple and double quotes is !

    Anyway, I found the solution by looking at PHP's source code. I was wrong: nl2br replaces \n with <br>\n and not \n<br>, so I did a simple str_replace("<br />\n","\n",$post) and it works now
    i do the same using str_replace('<br />', '', $text).

  7. #7
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup, but I needed to delete <br /> only when they're at the end of a line, not when they're inside of one.
    Otherwise, I'd have used your function in the first place.
    [blogger: zengun] [blogware contributor: wordpress]


Bookmarks

Posting Permissions

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