I have a simple HTML page and I feel unsure about which is the best place to put a PHP block that loads 2 JSON arrays from files so that they can then be passed on to JavaScript variables.
I have placed it here, but I have no criteria:
<!DOCTYPE html>
//i have placed the block here
<?php
$twit_collection=file_get_contents('cdtwbot_twit_collection.json');
$tag_collection=file_get_contents('cdtwbot_tag_collection.json');
?>
<html>
<head>
<script type="text/javascript">
//pass PHP variables declared above to JavaScript variables
var twit_collection = <?php echo $twit_collection; ?>;
var tag_collection = <?php echo $tag_collection; ?>;
</script>
</head>
<body>
//document continues...
</body>
</html>
Would it be better placed inside the <head>
tag? Or somewhere else?
There is a great post about passing variables from PHP to JavaScript here but it doesn't cover this point.