php3-php4 mysql problem with nl2br coding
| From: | Terry Romine | Date: | Fri, 23 Nov 2001 20:04:00 +0000 |
| Subject: | php3-php4 mysql problem with nl2br coding | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-14559@lists.php.net to get a copy of this message | ||
I seem to have run into a strange bug where when I enter text through a form, and use the nl2br call in PHP, instead of getting "<BR>" I get "<BR />" and then my parsing fails on the display side (where I use ereg_replace("<br>","", $string) to clean up the breaks.
sample code:
Entry Form
$c_title = addslashes($c_title);
$c_content = addslashes(nl2br($c_content));
$sql = "update $tableName set
c_title='$c_title',
c_content='$c_content'
where c_id=$itemID";
if(!($result=mysql_query($sql, $link))) {
echo("ERROR 109 $sql<br>\n");
exit();
}
and display
$sql = "select * from $tableName";
$result = mysql_query($sql) or die("ERROR: $sql");
while ($row = mysql_fetch_object($result)) {
echo("<tr>");
$myTitle[$j] = $row->c_title;
$myContent = stripslashes(ereg_replace("<br>","",$row->c_content));
echo("<td colspan=2><hr><br>
<p><font size='2' face='Verdana, Arial, Helvetica, sans-
serif'><b>$myTitle[$j]</b></font></p>
<p><font size='2' face='Verdana, Arial, Helvetica, sans-
serif'>$myPhoto1 $myContent $myPhoto2</font></p>
$myPhoto3
<hr></td></tr>");
}