944,028 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 20223
  • PHP RSS
Aug 30th, 2005
0

Output MySQL text field formatted

Expand Post »
Hi,

I have a text data type field in MySQL table that I need to read out to a page. When the value is entered into this text field the value will have returns as follows:

------------------
TEST TEST aaaaaaaa

asdasdasdfas

3rd lineasadas
----------------
When I read this value out and display in php page in the browser, the returns are not there and I get it all in one line:
-----------------------
TEST TEST aaaaaaaaasdasdasdfas3rd lineasadas
-------------------

What can I do to have he returns show up?

Thanks,
Juls
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Juls is offline Offline
3 posts
since Jun 2005
Sep 1st, 2005
0

Re: Output MySQL text field formatted

In the webpage you can use str_replace:

$text = $row['text'];
$text = str_replace("\n", "<br>", $text);
echo $text;

To prnt in one line, ignore the str_replace part.
Reputation Points: 10
Solved Threads: 7
Posting Whiz in Training
zippee is offline Offline
294 posts
since Jan 2005
Sep 2nd, 2005
0

Installation MySql

Sir,

I am new to MySql.

I am facing Installation Problem.

Kindly do the Needful.

Ashwin Perti
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ashwinperti is offline Offline
22 posts
since Aug 2005
Sep 3rd, 2005
0

Re: Output MySQL text field formatted

Juls - PHP has a built in function to convert line feeds to <br /> elements. It is nl2br, and it's use is:
[PHP]echo( nl2br("this is a line\nthis is another line") )
/** prints as
this is a line<br />
this is another line
*/[/PHP]

ashwinperti - suggest you start your own thread rather than trying to hijack others. You'll get a better response if you describe what your problem is and what your operating environment is.
Reputation Points: 16
Solved Threads: 7
Junior Poster
Lafinboy is offline Offline
166 posts
since Jul 2004
Apr 10th, 2010
0
Re: Output MySQL text field formatted
nl2br is the function which assist you to change enter as jump line.

Hope it helps

Click to Expand / Collapse  Quote originally posted by zippee ...
In the webpage you can use str_replace:

$text = $row['text'];
$text = str_replace("\n", "<br>", $text);
echo $text;

To prnt in one line, ignore the str_replace part.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Mckcvision is offline Offline
7 posts
since Apr 2010
Apr 10th, 2010
0
Re: Output MySQL text field formatted
nl2br is the function to replace enter with <br>
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Mckcvision is offline Offline
7 posts
since Apr 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Associative Array of States and Countries
Next Thread in PHP Forum Timeline: Help adding rel tag to dynamic image path





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC