[SOLVED] str_replace() doesn't pass "<br>".

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

[SOLVED] str_replace() doesn't pass "<br>".

Post by $var »

Code: Select all

if($_POST['bpress']=="add")
	{
        $str1 = str_replace("\r\n", "<br>", $_POST['question']);
		$sql = "INSERT INTO about_faq (
		About_F_Q,
		About_F_A) 
		VALUES (
		'".$str1."',
		'".$_POST["answer"]."')";
The info in the field passes, but it doesn't register the spaces between paragraphs.
Last edited by $var on Wed Sep 21, 2005 3:20 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

maybe they aren't \r\n ;)
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post by ryanlwh »

use nl2br()
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Wrong parameter count for str_replace()?

Post by $var »

Code: Select all

$str1 = str_replace("<br>", $_POST['question']);
Wrong parameter count for str_replace()?
What does that mean?
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Re: Wrong parameter count for str_replace()?

Post by ryanlwh »

$var wrote:

Code: Select all

$str1 = str_replace("<br>",);
Wrong parameter count for str_replace()?
What does that mean?
str_replace requires 3 parameters... you're giving it only 2...

why not use $str1 = nl2br( $_POST['question'])
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

whoops... i figured it out.
i had the str_replace on the question, not the answer!

duh.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

thanks ryan!

it's crazy how many flippin' intricacies there are in PHP
Post Reply