@alexdeefJun 25.2014 — #PHP code is executed on the server side and output data are transmitted to Web browser.
JavaScript script code is executed by the browser on user's computer.
Combining these two web programming languages, JavaScript scripts can achieve dynamic results based on data received and processed by the server. Thus, the same web page can contain a JavaScript code for a user and other JS code for another user.
- There are two ways to combine PHP with JavaScript to achieve a dynamic and personalized result:
1) By writing the entire JS script within PHP code and adding it to the web page with PHP function "echo" (or "print").
@suchetagajdevaJul 09.2014 — #PHP has not changed the state of HTML labels and codes in any capacity, so you can embed a bit of javascript code into a php document precisely the same way you destroy it html record. PHP just permits you to stamp certain parts of a php document as php code which will be interepreted by php program before it is send to the customer program
@jedaisoulJul 09.2014 — #To clarify what others have said here:
1. A PHP file is essentially an HTML file with the file extension .PHP instead of .HTML. It is given that extension to tell the web server that it contains PHP code that should be executed before the HTML is passed to the web browser.
2. A PHP file can contain HTML and JavaScript, that is passed to the browser "as is".
3. A PHP file can contain HTML and JavaScript that is dynamically generated and passed to the browser.
4. The HTML and JavaScript is passed in either of two ways:
a) It can be echo'd directly from the PHP code. E.g. <i> </i><?php /* some php code*/ echo '<div id="example">'; /* some more php code */
b) The php interpreter can use "?>" to drop into HTML mode then "<?php" to return to PHP mode. E.g.: <i> </i><?php /* some php code*/ ?> <!-- this is html code --> <div id="example"> <?php /* some more php code */