-1

I have below code in php

<? php 

   $articleContent = "  Blah ..
                        The game is on 
                        Foo ";
?>

Also I have below JavaScript Code Also

<script>

  var articleContent = "{$articleContent}";  // from php     
  /* I WANT TO USE THIS  articleContent variable , but it cannot take it , it displays a ILLEGAL token error due to multi line string !*/
</script>

1 Answers1

1

Try my code

<?php 

   $articleContent = '  Blah ..
                        The game is on 
                        Foo ';

?>

<script>
  var articleContent = <?php echo json_encode($articleContent); ?>     
  alert(articleContent);
</script>
ImBhavin95
  • 1,494
  • 2
  • 16
  • 29