Jump to content

str_replace Question

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Guest_Grouchotron_*

Guest_Grouchotron_*
  • Guests
So, I'm passing a value from php to javascript, the value originally is taken in from a form, is stored in mysql, and is pulled out by the php code to get passes to the javascript.

Here's my code:

$value2 = str_replace(array('"',"'", "\r", "\n", "\0", "<br />"), "", $value2);
$value2 = str_replace("\n","\\n",$value2);
$value2 = str_replace("\r","\\r",$value2);
echo "entries[$key][$key2] = '$value2';\n";

I'm getting an unterminated string contant error, and when I look at page source I see that the php has written a newline after $value2 and before the closing ';

What am I doing wrong in escaping newlines? Is there some other character I need to be escaping?

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
What is an example of what $value2 contains?
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.