I\'m generating a string in PHP and then eventually passing this string into a JavaScript alert box, my problem is I actually can\'t add line breaks in my alert box.
My c
You need to change $str to
$str
$str = "This is a string\\n";
so that the \n gets passed to the JavaScript.
\n
This happens because PHP interprets the \n before JavaScript has the chance to, resulting in a real line break inside the Javascript code. Try
\\n