Live preview: parsing carriage returns

JavaScript and client side scripting.

Moderator: General Moderators

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

Post by $var »

wow, so over a year later... and i'm back checking out how to do a string replace to eliminate apostrophes in database entries.
this is what i've got: str_replace("&#39","'",'<br />',$_POST["solution"])
i need it to allow "'" and replace line breaks with "<br />"

thank you!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

str_replace() takes three arguments. You're giving it four.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

i get it now,
str_replace($search, $replace, $_POST["solution"]);

but you can search a few things, and replace them appropriately, as long as they are in matching order in an array?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm not sure what you're asking. You are allowed to pass arrays.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

hmm... someone else told me to do this... and it sorta work:

Code: Select all

$search = array("'", "<br />");
	$replace = array("&#39", "\n");
	$solution = str_replace($search, $replace, $_POST["solution"]);
i think something else may be wrong, because i'm still getting a syntax no-no, but, the echo appears correct.
Post Reply