Results 1 to 5 of 5

Thread: [RESOLVED] Problem: showing text in new line

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2006
    Location
    Iran
    Posts
    48

    Resolved [RESOLVED] Problem: showing text in new line

    Hi my dear
    I have a problem in php/mysql
    For example I write below text to textarea and save it to mysql:
    Code:
    Hi
    I am ShaMSofT
    and i like programming
    
    bye bye
    now i want to retrieving my data from mysql and use echo function to show it. like:
    Code:
    //save mysql data in $text
    echo $text;
    but this statement show below data:
    Code:
    Hi I am ShaMSofT and i like programming bye bye
    i see my data in table of mysql and data saved all right like first code. now i do not know why php show it like third code
    help me,please

    thanks to all reader this topic

    --------------------
    sorry for bad my english
    Sorry For Bad My English

  2. #2
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802

    Re: Problem: showing text in new line

    If you look at the source code for the webpage you echo the text to you'll see the linebreaks. But the way html works is to ignore linebreaks in the source, that's why you see it as if it were all on one line. So solve it you need to use the nl2br() function in your php file
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Problem: showing text in new line

    PHP's default content type is text/html, but if you're not marking up HTML then just send it as plain text.

    PHP Code:
    // Add this before beginning output.
    header('Content-type: text/plain'); 

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2006
    Location
    Iran
    Posts
    48

    [Resolved]

    Thanks To McCain & penagate
    Sorry For Bad My English

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] Problem: showing text in new line

    No problem.

    Also, thanks for trying but the proper way to mark the thread resolved is using the Thread Tools menu above the first post. I did it for you this time.

Posting Permissions

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



Click Here to Expand Forum to Full Width