Jump to content


Photo

str_ replace


  • Please log in to reply
4 replies to this topic

#1 dmc2211

dmc2211
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 18 October 2006 - 02:32 PM

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:

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.


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.

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.

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?

#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 18 October 2006 - 02:34 PM

The returns are not removed you just don't see them, just use nl2br(), when you show the result coming out of the database!


me!

#3 dmc2211

dmc2211
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 18 October 2006 - 02:56 PM

just use nl2br(), when you show the result coming out of the database!


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

#4 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 18 October 2006 - 03:33 PM

\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

$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'] );
}



me!

#5 dmc2211

dmc2211
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 18 October 2006 - 04:06 PM

Got it thanks for all your help!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users