Coms 463 Php presentation



Coms 463 Presentation

Programming with PHP

By: Seth Larson

A little bit about PHP.

PHP is an acronym for Hypertext Preprocessor. PHP is a general purpose server side scripting language that is used in web development. PHP supports many different databases like MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc. The best thing about PHP is it is open source software, so it is free. The link to the download is . PHP files have file extension of ".php", ".php3", or ".phtml"

What do you need installed on your computer to use php?

To use PHP on your computer you need a server that supports PHP. Some servers that have the support are Apache(open source), IIS (Microsoft), and Oracle. The latest version of PHP can be found at .

| |

| |

| |

| |

| |

You can test if you already have support for PHP with the code on the right. Copy and paste it in notepad and then save to “C:\Inetpub\wwwroot” with the filename “phpinfo.php”. Type in a browser and the screen will look like the “phpinfo.php example” located at the end of the paper. If you get an error or don’t see anything your PHP is not working. The webpage will have all the information about your php configuration.

PHP scripts run on the server-side and are sent to the client in html form. The sever-side PHP script itself is embedded directly in the HTML. Likewise, you can embed HTML in the PHP script shown in below. The example prints “PHP rules” inside a HTML table. Echo is a print call in PHP.

| |

| |

| |

| |

| |

If you view the page source you will see that the server sent all the code in html which looks like this.

| |

| |

| |

| |

|PHP rules! |

| |

| |

| |

| |

PHP Syntax

All PHP scripting blocks begin with the tag “” and can be placed anywhere in html. PHP statements always end with a semicolon.

PHP variables

Variables are easy to create with PHP. Just like in other high-level languages there are syntax rules. Some predefined variables as well as predefined functions exist like echo, $GLOBALS, and $POST, php is no different. Variables in PHP have to start with “$” followed by a name, example $variable_name.

The code just below shows how to concatenate variables and also how to use the “\” character to print the name of a variable. The first php block shows how to use the “\” character. The character needs to be directly in front of the variable name, this tells the server to print what directly follows and not to treat it as a variable.

| |

| |

| |

| |

| |

The following code shows how to use the (.) dot operator to concatenate the var_C and var_D variables. The code shows how to use a forward slash followed by a asterisk (“/*”) and then an asterisk followed by a forward slash (“*/”) for a block comment A single line comment syntax is double forward slashes (“//”) followed by the comment.

| |

| |

| |

| |

| |

PHP operators

Operators, conditionals, and looping are the same as other high level languages

• Arithmetic Operators

+, -, /, *

• Assignment Operators

=, +=, -=, *=, /=, %=

• Comparison Operators

==, !=, >, =, ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download