Jump to content

Archived

This topic is now archived and is closed to further replies.

dmc2211

str_ replace

Recommended Posts

Hi,

I have set up a CMS to add properties.  There is a text area box to submit specifictions about the property. When I add the specifications to the text area it looks like this:

[b]Entrance Porch: :-Wooden floor.


Entrance Hall:- Wooden floor.


Lounge: 17' 5'' x 11' 11'' 5.31m x 3.63m. Wooden floor. Pine fireplace with cast iron inset. TV Point. Recess lighting.[/b]

The problem is when it submits to the database it eliminates the returns and when it displays from the database it looks like a paragraph e.g.

[b]Entrance Porch:-Wooden floor.Entrance Hall:- Wooden floor.Lounge: 17' 5'' x 11' 11'' 5.31m x 3.63m. Wooden floor. Pine fireplace with cast iron inset. TV Point. Recess lighting.[/b]

If I add "break tags"to the text before submitting to the database this displays correctly but I dont want to add these tags everytime I submit data to the database.


I was looking at str_replace().  Basically I would like to replace anywhere in the text that has ":-" with "break tags"

Any tips?

Share this post


Link to post
Share on other sites
The returns are not removed you just don't see them, just use [b]nl2br()[/b], when you show the result coming out of the database!


me!

Share this post


Link to post
Share on other sites
[quote author=printf link=topic=111905.msg453804#msg453804 date=1161182093]
just use [b]nl2br()[/b], when you show the result coming out of the database!
[/quote]

Where should I display this piece of code? I have a recordset and this pulls the description from the database.  Before the text was submitted to the database it had line breaks.  When the recordset pulls this from the database it loses these line breaks and looks like a paragraph.  I'm sorry all this is very new to me

Thanks

Share this post


Link to post
Share on other sites
\r or \n are never really seen in a html formatted page unless you use < pre >, but they are not lost either!

So when you run your query, you add the function nl2br(); on the return row of data that has the \r?\n in it's content

[code]
$query = mysql_query ( "SELECT my_column FROM my_table WHERE this = that" );

while ( $row = mysql_fetch_assoc ( $query ) )
{
$text = nl2br ( $row['my_column'] );

// or if you don't want resign the $row variable

$row['my_column'] = nl2br ( $row['my_column'] );
}

[/code]


me!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.