Tech Musings

Sunday, November 27, 2005

Formatting text returned from MySQL table fields.

When a users enters text into a text area field, line breaks are inputted along with the unformatted text. To maintain these "new line" breaks (returns) on a dynamic Web page, you need to replace the line breaks with the
tag. To do this, use str_replace like this:

$q1 = $row_Recordset1['tc_q1'];
$q1 = str_replace("\n", "
", $q1);
echo $q1;
?>

I used this technique on returned portfolio pages in the Pt. Loma project. Could also replace "\r".

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home