PJ Hile

Don’t worry, I’m from the Internet.

PJ Hile header image 4

Entries Tagged as 'Javascript'

Javascript strings over multiple lines from PHP

March 13th, 2008 · No Comments

I had a problem where I was defining javascript variables from php variables, and the php variables had multiple lines.
So, a function like this:
function SomeFunction() {
var variable = “<?php echo $variable; ?>”;
}

was creating this:
function SomeFunction() {
var variable = “The first row.
The second row.
The third row
“;
}

The fix was to replace all the ‘\n’ with ‘\\n’, so [...]

[Read more →]

Tags: Javascript · PHP