SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Formatting MySQL Data in PHP

    Hi,

    I have a mysql database, one of the fields which is set as a TEXT field, has data along the lines of

    line1<br/>line2<br/>this is a test<br/>

    The problem i'm having is when i echo this onto the PHP screen, it comes up as:

    line1 line2 this is a test

    Then if i look in the source code, the source code for the page is

    line1
    line2
    this is a test

    I want this to be reversed so I get the correct output on my PHP page and the tags in the source code, does anyone know how I can do this? I've looked through the PHP manual and tried different functions such as htmlspecialchars, however none of them seem to make a difference.

    Thanks

    Kev

  2. #2
    SitePoint Addict liquidautumn's Avatar
    Join Date
    Nov 2002
    Location
    Kharkov, Ukraine
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nl2br() converting newlines to HTML line break tags

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Hi, thanx very much that did the job on the line breaks however how do you convert &nbsp to spaces as well, I'm not the data entry person, some of the data is really messed up.

    Cheers

    Kev

  4. #4
    SitePoint Addict liquidautumn's Avatar
    Join Date
    Nov 2002
    Location
    Kharkov, Ukraine
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you may use str_replace("&nbsp;", " ", $string);
    ...if you really need it


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
  •