User Tools

Site Tools


en:web_development:media:javascript

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:web_development:media:javascript [2021/12/20 05:33]
mag
en:web_development:media:javascript [2023/08/16 09:33] (current)
Line 150: Line 150:
   * Variables in PHP are always represented by <html>$</html>and the variable name.   * Variables in PHP are always represented by <html>$</html>and the variable name.
   * In this case, we have a variable named 'page' and we assign it the value of 'media' which is the page name.   * In this case, we have a variable named 'page' and we assign it the value of 'media' which is the page name.
-  * Now open 'header.php' and replace the <html><script><html> line with the following.+  * Add a command to display the variable. 
 + 
 +<code><?php 
 +    $page = "media"; 
 +    echo $page; 
 +    include("header.php"); 
 +    include("menu.php"); 
 +?></code> 
 + 
 +  * When you save, upload and run the code, you'll see the word 'media' at the top. 
 +  * The code in 'header.php' is part of the same page, so we can use our variable there too. 
 +  * Now open 'header.php' and replace the <html><script></html> line with the following.
 <code>    <script src="<?php echo $page; ?>.js"></script></code> <code>    <script src="<?php echo $page; ?>.js"></script></code>
   * Notice that the only change we've made is to the word 'lists'. We've replaced it with PHP code saying to 'echo' (reproduce in the code) the value of the variable 'page'.   * Notice that the only change we've made is to the word 'lists'. We've replaced it with PHP code saying to 'echo' (reproduce in the code) the value of the variable 'page'.
en/web_development/media/javascript.1640007194.txt.gz · Last modified: 2023/08/16 09:33 (external edit)