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.

  1. Simple include:

    To include the contents of one file into another:

    <?php include "myfile.php"; ?>
    
    
    
    
  2. How to set vaiables

    <?php $majorSection="Contact Us"; $minorSection="Overview"; ?>
    
    
  3. How to write text to the browser

    <p><?php echo "Hello World"; ?></p> 
    
  4. How to write variables to the browser

    
    <p><?php echo "Hello World"; ?></p> 
    
  5. How to join text together

    Using the "." character you can concatenate strings and variables

    <?php
    echo "Hello" . " Rachel";
    ?>
    
  6. 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>";
    }
    ?>
    
    
  7. 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']; ?>
    " />
    
    
X
dreamhost.com