Jump to content

[SOLVED] str_replace!


DJTim666

Recommended Posts

I need to know why the following code isn't working for me. It is supposed to take enter's and insert them into the DB as < br / >

 

Code:

<?php
<tr><td width='80%'><textarea cols='40' rows='4' name='p_message'></textarea></td></tr>
$p_message = $_POST['p_message'];
$replaceit = array(BAD WORDS =O!);
$replaceit2 = array("*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****", "*****","*****", "*****");
$donereplace = str_ireplace($replaceit, $replaceit2, $p_message);
$safe_p_message = mysql_real_escape_string(strip_tags($donereplace));
$safe_p_message2 = str_ireplace("\n", "<br />", $safe_p_message);
mysql_query("INSERT INTO forum_posts (post_name, post_msg, time_posted, top_id) VALUES('" . $Yourname . "', '" . $safe_p_message2 . "', '" . $currentime . "', '" . $topic_id . "')");
?>

 

The variables that you don't see defined here, are defined in my core file.

 

--

DJ!

Link to comment
Share on other sites

This code is for a forum that I coded. RIght now the database holds;

 

hello

 

hello

 

testing!

 

I want it to be holding;

 

hello

< br / >

< br / >

hello

< br / >

< br / >

testing!

 

My string holds the content for the textarea. It's for replies to a topic.

Link to comment
Share on other sites

I got it to work when I display the data from the database. But when I use str_replace() to insert data into the DB it should be putting a < br / > on every linbreak. Any idea why that's not working?

 

I suggest you use nl2br upon outputting what's in the database. You should always store a copy of the original content.

Link to comment
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.