<?php //php code.. $some_var ='value'; ?> <!doctype html> <html lang='en'> <head> <meta charset='utf-8' /> <title>Page Title</title> <script> var js_var ='<?php echo $some_var; ?>'; </script> </head> <body> Page content.. <script src='external_file.js'></script> </body> </html>
Now, in the script from external_file.js we can use the js_var
(it contains the value of the php $some_var).
2. For example, in external_file.js:
alert(js_var); // value
The javascript variable must be defined before the external js file is included.
<object type="application/x-shockwave-flash" data="file.swf" width="500" height="250"> <param name="src" value="file.swf" /> Your browser not support SWF. </object>
input:focus { background-color: #88fe88; }
var jsnstr = '{"url": "http://coursesweb.net/", "title": "Web Development Courses"}'; var obj = JSON.parse(jsnstr); alert(obj.url);
if (file_put_contents("file.txt", "content")) echo "The file was created"; else echo "The file can not be created";