To Javascript String


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2.  
  3. // example usage
  4.  
  5. <script type="text/javascript">
  6. var str = '<?= to_js_string($html) ?>';
  7. </script>
  8.  
  9. */
  10.  
  11. function to_js_string($str) {
  12. return str_replace(array("\\", "'", "\r", "\n"), array('\\\\', "\'", ' ', ' '), $str);
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.