Escaping line break (endline) from PHP variable for Javascript usage

javascript, php

Solution

You can remove it by replacing it with nothing,

str_replace("\n","",$row['name']);

If you need your line break to be in your JS string you can double escape it,

str_replace("\n","\\n",$row['name']);

Problem

heres my code : ``` <td onclick="openFile('<?php echo htmlentities ($row['name'])?>',' <?php echo htmlentities ($row['content'])?>')"> <a href="#nf" data-toggle="tab"><?php echo $row['name']?></a></td> ``` as there is an endline char in $row['content']: openFile('wow','wow wow wow '); and when browser cant find an ending qoutes in the same line it throws an error(SyntaxError: unterminated string literal [Break On This Error]). Any solution for this ?

Original source