PHP is a simple, yet very powerful server-side scripting language. You write HTML pages and sprinkle little bits of PHP code in between "<?php" and "?>" and magic happens.
- Simple include:
To include the contents of one file into another:
<?php include "myfile.php"; ?>
- How to set vaiables
<?php $majorSection="Contact Us"; $minorSection="Overview"; ?>
- How to write text to the browser
<p><?php echo "Hello World"; ?></p>
- How to write variables to the browser
<p><?php echo "Hello World"; ?></p>
- How to join text together
Using the "." character you can concatenate strings and variables
<?php echo "Hello" . " Rachel"; ?>
- How to define a method and invoke it from a page
<?php function writeSubLink($current,$minor,$target) { echo "\n<li class=\"leftpane\">"; if($current == $minor) { echo "<span class=\"navlinks_sub\">$current</span>"; } else { echo "<a href=\"$target\" class=\"navlinks_sub\">$current</a>"; } echo "</li>"; } if($majorSection == "Our Services"){ echo "<ul>"; writeSubLink("Options Counseling",$minorSection,"counseling.php"); writeSubLink("Support Services",$minorSection,"services.php"); echo "</ul>"; } ?> - How to access name value parameters on the url
You can use "$_GET[]". For example if the url is "http://www.fincher.org/news/photo.php?pic=2007/originals/2007-08-30-2151-IMG_5649.JPG". Then the following will pluck the variable "pic" from the url and replace its value as the src for the image.
<img src=" <?php echo $_GET['pic']; ?> " />
