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 code looks as follows
$str = "This is a string\n";
$alert = $str."This is the second line";
if(!empty($alert)){
?>
<script type="text/javascript">
$(document).ready(function() {
alert('<?=$alert?>');
});
</script>
<?php
}
I'm getting the error:
Undeterminnated string literal
If I remove the \n
from the string it works 100% but without line breaks.