Jump to content

Help on str_replace


shamuraq

Recommended Posts

Hi...

I read on php.net manual that its better to use str_replace than preg_replace. I used

 

$summary = clean($_POST['summary']);

$summary = nl2br($summary);

to convert the carriage return(is that the correct term?) to insert them into mysql. So naturally, i want them converted into <br> when i pull them from mysql.

 

I used this:

$num_rows=mysql_num_rows($result);
	if($num_rows == 0){
	}
	else{
		for($x = 0; $x < $num_rows; $x++){
		$row = mysql_fetch_assoc($result);
		$id = $row['id'];
		$position = $row['position'];
		$summary = $row['summary'];

$order   = array("\r\n", "\n", "\r");
$replace = '<br />';
$newstr = str_replace($order, $replace, $summary);

 

But i got this error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/...php on line 310

Is it a syntax error?

 

Thanx in advance...

Link to comment
https://forums.phpfreaks.com/topic/255039-help-on-str_replace/
Share on other sites

nl2br already coverts newlines to <br /> tags.

 

You shouldn't do this on the way into the database however, only on the way out.

Followed ur advice and removed the nl2br from the insert into sql file. But am still getting the same error.

Link to comment
https://forums.phpfreaks.com/topic/255039-help-on-str_replace/#findComment-1307736
Share on other sites

Archived

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

×
×
  • 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.