PHP

PHP stands for "PHP hypertext preprocessor".  It's a recursive acronym, just like xinu.  Before that it stood for "personal home page" tools, and started because Ramus Lerdorf wanted to keep track of who was looking at his resume.

The goals of PHP are simplicity, a natural way of using databases, and platform independence.  Also, it's open source.

Basic Method

Embed code within the html page.  Make sure the file is parsed by the httpd serer on the server (generally by ending it with .php).  Have the server (not the client) execute the code.  Replace the code with the output of the code, and send the result the to the client.

Why execute on the server?

But

Hello World

<HTML>
<?php
        echo("Hello world");
?>
</html>

All php code goes into a <?php ...> tag.  Or it can go into a <% ... > to lokk like an A.S.P. page.  Or it can go into <SCRIPT language=php> ... </script>.
You can have any number of php tags in your page.  You can find this page  here.

Hello World With Forms

<html>
<form>
Please type your name here:<br>
<input type=text name=username><br><br>
<input type=submit value="Run the script">
</form>
You typed:
<?php
echo($_REQUEST["username"]);
?>
</html>



Note that there is no "action=" for the form.  Instead, the form gets redirected back to this same page after the submit button is hit, only this time with the variable "username" filled in.  If you want to go to a different page, then fill in the "action=" part of the form.  In fact, notice how the URL of the page changes as you type different things into the form, and then hit the submit button.  You are allowed to change the method of the form with the <form method=post>

If you use the default get method

If you use the POST method

Comments and Quotes

Within php code you can use //, #, or /* ... */.
Within HTML code you can use <!-- ... -->
In real life you can use <BOGUS ... >, but that's bogus.  Any unknown tage will work, but that's bogus.

To escape special chars, use \.  Special chars include ' " \ $

To avoid variable expansion, use ' instead of ".