Jump to content

trouble replacing carriage returns with br tag


surreal5335

Recommended Posts

I am working on creating a post that will replace all carriage returns with a <br /> tag so the format the user entered will be preserved.

 

here is the code I am using for my create_post() and the str_replace() for replacing carraige returns.

 

$body = str_replace("\r","<br />",$_POST['txt']);

/************************************************************************/
  function create_post($params)
  {
    $connection = db_connect();
$body;
    $query = sprintf("INSERT INTO comtable SET
                          title = '%s',
                          name = '%s',
                          txt = '%s',
                          email = '%s',
                          time = NOW(),
                          user_id = '%s'",
                          mysql_real_escape_string($params['title']),
                          mysql_real_escape_string($params['name']),
                          mysql_real_escape_string($params['txt']),
                          mysql_real_escape_string($params['email']),
                          mysql_real_escape_string($params['time']),
                          mysql_real_escape_string($params['user_id']));
    $result = mysql_query($query);
    if (!$result) return false;
    else return true;
  }

 

here is my post page for displaying the database results:

 

<?php include_once('model/post.php'); ?>
<table width="400" border="1">
<tr>
<td>
<h2><?php echo $post['title']; ?></h2>
</td>
</tr>

<tr>
<td>
name: <?php echo '<a href="'.$post['email'].'">'.$post['name'].'</a>'; ?>

<!--date created: <?php echo $hr.':'.$min.' '.$timetype.' '. $mo.'/'.$da.'/'.$yr; ?>-->

post id: <?php echo $post['post_id']; ?>
</td>
</tr>

<tr>
<td>
comment: <br/> <?php echo $body; ?>
</td>
</tr>
</table>

 

The file included is the one containing the create_post() and $body. It seems to me right now I am not getting any database data in $body, just the function to replace the returns with <br />. The form that is getting this data and the returns from the user is below:

 

    <textarea cols="40" name="post[txt]" rows="5"></textarea>

 

obviously there is more, but this is the relvent part.

 

The method of the form is set to "post"

 

I appreciate the help

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.