Skip to content

Instantly share code, notes, and snippets.

@LukasRos
Created April 29, 2014 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LukasRos/11404051 to your computer and use it in GitHub Desktop.
Save LukasRos/11404051 to your computer and use it in GitHub Desktop.
Passing data from PHP to JS
<?php
$data = array('key1' => '</script>', 'key2' => 'hello world');
?>
<html>
<head>
<title>Test</title>
<script type="text/javascript">
var data = <?php echo json_encode($data); ?>;
</script>
</head>
<body>
<h1>Test</h1>
<script type="text/javascript">
alert(data['key1']);
alert(data['key2']);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment