Jump to content

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

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.