php function to echo javascript string

Solution

Use heredoc syntax for multiline strings.

Heredoc behaves like a double-quoted string, so you don’t need to escape quotes inside it:

$text = <<<EOD
This is a “heredoc” example.
You can include “quotes” and variables like $variable without escaping.
EOD;

echo $text;