In the index.html file there is an ordinary script, inside which is the js array (which is generated by the foreach loop from php).

<script type="text/javascript"> var cams = [ <?php foreach ((array) $this->data['video_streams'] as $video_stream): ?> { type : "html", title : "<?php echo addslashes($video_stream['name']); ?>", content : "<?php echo addslashes($video_stream['html']); ?>", }, <?php endforeach; ?> ]; </script> 

The bottom line is that I have another script stored in the $ video_stream ['html'] variable, which is played directly from the array. I would be very grateful if you tell me how it can be screened? I tried to add addslashers () , but it (the script) is still playing, but this time with errors due to slashes.

  • one
    don't you want to do something a la var cams = <?= json_encode($this->data['video_streams']) ?> ? for generating arrays in cycles on pHP is not somehow not very :) - teran
  • @teran in fact, I have already done everything for a long time with the usual Ajax request, switching cameras. But alas, the manager didn’t like this method and made him do it with a pre-prepared array on js. Although there is no visible difference in the download at all. - Demian Shumilov
  • @teran however, your method worked fine, thanks :) - Demian Shumilov
  • if there is no difference, and the data can be prepared immediately, then why send extra requests to the server? from this point of view, the head of rights. - teran
  • @teran no one argued, I completely agree. - Demian Shumilov

0