Return to Snippet

Revision: 8059
at August 31, 2008 22:09 by section31


Updated Code
/*

// example usage

<script type="text/javascript">
var str = '<?= to_js_string($html) ?>';
</script>

*/

function to_js_string($str) {
  return str_replace(array("\\", "'", "\r", "\n"), array('\\\\', "\'", '  ', '  '), $str);
}

Revision: 8058
at August 31, 2008 22:08 by section31


Updated Code
/*
// example usage
<script type="text/javascript">
var str = '<?= to_js_string($html) ?>';
</script>

*/
function to_js_string($str) {
  return str_replace(array("\\", "'", "\r", "\n"), array('\\\\', "\'", '  ', '  '), $str);
}

Revision: 8057
at August 31, 2008 22:04 by section31


Updated Code
function to_js_string($str) {
  return str_replace(array("\\", "'", "\r", "\n"), array('\\\\', "\'", '  ', '  '), $str);
}

Revision: 8056
at August 31, 2008 22:04 by section31


Updated Code
function to_js_string($str) {
return str_replace(array("\\", "'", "\r", "\n"), array('\\\\', "\'", '  ', '  '), $str);
}

Revision: 8055
at August 31, 2008 21:56 by section31


Initial Code
function to_js_string($str) {
  return str_replace(array("'", "\r", "\n", "\\"), array("\'", '  ', '  ', "\\\\"), $str);
}

Initial URL

                                

Initial Description

                                

Initial Title
To Javascript String

Initial Tags

                                

Initial Language
PHP