Forums

PHP

This topic is locked

Spaces and Breaks in php

Posted 25 Sep 2002 11:54:49
1
has voted
25 Sep 2002 11:54:49 Saeed Abdi posted:
I have a very small problem but as they say it's only easy when you know how, I have small mysql database and I'm using php to insert and display the db, my problem is when I display the record in the db there are no spaces or paragraphs only one continuous line, but if I query the db using command line it gives me the data properly formatted, so my question is how do I display this as it's shown in the db


Example of what my php is showing
Gujarat state Wednesday to prevent any outbreak of rioting after the temple bloodshed. Gujarat state saw vicious religious rioting earlier this year, after a Muslim mob set fire to a train carrying Hindu activists in February. That attack set off a wave of reprisal killings and rioting in which Muslims were the main victims. In total, about 1,000 people were killed over three months, according to government estimates.

Return is represented by \r\n\r\n in the db
<img src=../images/dmxzone/forum/icon_smile_sad.gif border=0 align=middle>

Replies

Replied 25 Sep 2002 16:35:46
25 Sep 2002 16:35:46 Brent Colflesh replied:
Dear Xlarge,
Check out:

www.php.net/manual/en/function.nl2br.php

Regards,
Brent

Replied 26 Sep 2002 11:11:02
26 Sep 2002 11:11:02 Saeed Abdi replied:
After reading and going through the link you kindly provided, I think this is the bit of code I need
$s_data = ereg_replace("(\r\n|\n|\r)", "&lt;br /&gt;", $s_data);
But my question is where do I put it, I've tried few things and keeps spitting out error messages
Replied 26 Sep 2002 13:16:07
26 Sep 2002 13:16:07 Julio Taylor replied:
the solution to this is really simple.

this is the code before you apply the nl2br tag:
<pre id=code><font face=courier size=2 id=code>
&lt;?php echo $recordset-&gt;Fields("field"?&gt;
</font id=code></pre id=code>

and this is after:
<pre id=code><font face=courier size=2 id=code>
&lt;?php echo nl2br( $recordset-&gt;Fields("field") ?&gt;
</font id=code></pre id=code>

that will respect any line breaks and spaces you included in the original BLOB field in the MySQL database. <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

------------------------
Poolio

MSN:

www.eliziumdesign.com
Replied 26 Sep 2002 15:39:28
26 Sep 2002 15:39:28 Saeed Abdi replied:
Thanks mate, I got it to work with your help of course. As they say it's only easy when you know how <img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle>
Replied 26 Sep 2002 16:55:17
26 Sep 2002 16:55:17 Julio Taylor replied:
no worries man! that's what we're here for <img src=../images/dmxzone/forum/icon_smile_tongue.gif border=0 align=middle>

------------------------
Poolio

MSN:

www.eliziumdesign.com

Reply to this topic