error with arlert function that I created

3

I have created a very simple alert function in php. It works, however, with a problem.

Whenever I call it like this:

Alert("Pedido finalizado");

It works, but when I put a \ n to have a break if line, it does not work. Example:

Alert("Pedido \n finalizado");

Does anyone know what it can be? in the browser the only error that appears and this:

SyntaxError: Unexpected EOF

Good follows the function:

function Alert($msn){
?>
<script>
    alert('<?=$msn?>');
</script>
<?php
}
    
asked by anonymous 15.08.2016 / 15:17

1 answer

3

That's what's happening:

<script>
    alert('Pedido
finalizado');
</script>

To solve this, \ would have to be escaped with a \ .

Alert("Pedido \n finalizado");

And so:

<script>
    alert('Pedido\nfinalizado');
</script>
    
15.08.2016 / 17:11