alert("This is line one\nThis is line two");
Reproducing With PHP
At first glance your initial thought on outputting the above using PHP might be to do something as follows:
echo "alert('This is line one\nThis is line two');";
Go ahead, give it a go and you’ll see that the new line is infact ignored and actually results in an error being generated.
Solving this is easier than you might think. Simply add a second backslash before the existing one as shown below:
echo "alert('This is line one\\nThis is line two');";