Forum Moderators: coopster

Message Too Old, No Replies

str_replace not working

         

benj0323

4:40 pm on Jul 24, 2004 (gmt 0)

10+ Year Member



I'm trying to store a database value into a javascript variable, like below:

fsseditor.Value = '$text[body]';

So in order to prevent javascript errors I have to do multiple str_replace's, like below:

$_POST['body'] = str_replace("\r\n",'',$_POST['body']);

$_POST['body'] = str_replace("'","\'",$_POST['body']);

It's removing all of the \r\n but its not even touching the single quotes.

Is there any other way I can accomplish the same effect?

Any help is greatly appreciated. Thank you!

benj0323

4:44 pm on Jul 24, 2004 (gmt 0)

10+ Year Member



Ok, I fixed my own problem. I was using $_POST[body] instead of $text[body]. Sorry, apparently I'm an idiot. But Im still curious if there is a more professional way to accomplish this same effect instead of using multiple str_replaces.

Thanks!

jatar_k

5:04 pm on Jul 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well, you're not an idiot, that's for sure. I am far beyond being able to count the number of times I have done the same thing.

the str_replace for quotes could probably just be replaced with add_slashes though depending on where it is going after you may want use mysql_escape_string.

Are you just chopping \r\n? str_replace is fine for that but there may be alternatives if there are other things that need to go as well. You could also look at the settings on the input method, I think textareas can be set to not send newlines.