Forum Moderators: open
<script>
function createHTML(str) {
// my function that dynamically creates new HTML
}
var html = '
<div class="test">
<script>
alert('Hello Wold') ;
var html2 = '
<div class="test2">
<script>
alert('I Fail') ;
</script>
<div>
' ;
createHTML(html2) ;
</script>
</div>
' ;
createHTML(html) ;
</script>
function js_string($string, $delim = "'") {
// order of operations is important!
// add slashes before all existing slashes
$string = addcslashes($string, "\\") ; // the first slash for php
// add slashes before all delim chars
$string = addcslashes($string, $delim) ;
// add a slash to ending script tags
$string = str_replace('</script>', '<\/script>', $string) ;
return $string ;
}