Some Simple PHP Examples ---------- I use BBEdit to code html and PHP, and in fact most of my writing it color codes text for html and will check syntax ---------- since PHP runs from a server the text files must first be moved there if there is a local installation of MAMP the server folder will be "Applications/MAMP/htdocs" and the files can be simply saved or dragged there for these examples I have uploaded to my webserver "ImagoMundi.com" at Dreamhost to see the interpreted results, access the files with a web browser for example: use Chrome to load http://ImagoMundi.com/php_examples/hello_world.php ---------- BBEdit has two very handy tools - built-in ftp and web browser to upload the current file to the server using ftp ========== the most common statements are print and echo (do the same thing) document = "hello_world.php" ---------- the most common errors (revealed at runtime) are due to missing quotes and semi-colons try the document "unquoted_hello_world.php" to see the error message for leaving off a " and the document "no_semicolon_hello_world.php" for the effect of leaving off a ; ---------- php is frequently used to place variable data within text document = "I_have_two_cats.php" these values could also be pulled from a database ---------- php can bring in chunks of code from template documents a plain text file with html tags, named "cat_story_one.inc", is in the folder "cat_stories" the following provides an html framework, with the cat story variable data in the middle document = "story_of_two_cats.php" Cat Stories "; require ('cat_stories/cat_story_one.inc'); print " "; ?> note the use of \ to escape the quotes try the document "unescaped_cat_story.php" to see the error message for one missing \ ---------- data such as text and dates can be manipulated document = "playing_with_dates.php" $American_formatted_date

"; $International_formatted_date = date('j F, Y', $unix_date); print "

$International_formatted_date

"; ?> note the use of parentheses and single quotes ---------- a trick that I use a lot is to derive information from the filename document = "Orinda_city.php"