Results 1 to 4 of 4

Thread: Formating text in mySQL article

  1. #1
    Join Date
    Feb 2003
    Posts
    1

    Question Formating text in mySQL article

    Newbie questions.
    When i enter in an article lets say in my databse and then output it on my site, there is no formating, just one big paragraph. Can someone tell me the best way to format the text? Im using DW MX, PHP, Mysql. Thanks again

  2. #2
    Join Date
    Dec 2002
    Location
    Cape Town, South Africa
    Posts
    75
    I just replace the newline character (which doesn't display in HTML) with a <br> tag, which does, as follows:

    PHP Code:
    $content str_replace("\n","<br>",$content); 

  3. #3
    Join Date
    Feb 2003
    Location
    Johannesburg, South Africa
    Posts
    145

    Post

    You could also save the text with HTML tags. When you do this, you should that the script validate the text first to exclude unwanted tags - basically the same way this forum works.

  4. #4
    Join Date
    Dec 2002
    Location
    Cape Town, South Africa
    Posts
    75
    Saving the <br> tag in the db is fine if you're only using the text for display on web pages, as nicc777 says. If you plan to use the data for feeds etc, then it makes more sense to leave it untouched, and format it when you need it. Probably better than my earlier piece of code is the function:

    string nl2br ( string string)

    This returns a string with '<br />' inserted before all newlines (which is XHTML compliant)

Posting Permissions

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