<?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>
Acum, in scriptul din external_file.js se poate utiliza js_var
(care contine valoarea variabilei din php, $some_var).
2. De exemplu, in external_file.js:
alert(js_var); // value
Variabila javascript se defineste inainte de includerea fisierului extern js.
<ul> <li>http://coursesweb.net/html/</li> <li>http://www.marplo.net/html/</li> </ul>
.some_class { display: list-item; }
var obj = { "courses": ["php", "javascript", "ajax"] }; var jsonstr = JSON.stringify(obj); alert(jsonstr); // {"courses":["php","javascript","ajax"]}
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>'; $dochtml = new DOMDocument(); $dochtml->loadHTML($strhtml); $elm = $dochtml->getElementById("dv1"); echo $elm->nodeValue; // CoursesWeb.net
I`m living here. - Traiesc /Locuiesc aici.
Estoy viviendo aquí. - Traiesc /Locuiesc aici.