Posted By

section31 on 08/31/08


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

jdstraughan
JimiJay
bryandease


To Javascript String


 / Published in: PHP
 

  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  

You need to login to post a comment.