<? $var = "el paco pepe pelo"; $var = str_replace("\r\n", '\n', $var); ?> <script type="text/javascript"> alert("<?=$var?>"); </script>