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
https://forums.phpfreaks.com/topic/65621-solved-str_replace/
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
https://forums.phpfreaks.com/topic/65621-solved-str_replace/#findComment-327715
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
https://forums.phpfreaks.com/topic/65621-solved-str_replace/#findComment-327728
Share on other sites

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.