Jump to content

str_ replace


dmc2211

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?
Link to comment
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
Link to comment
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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.