# Strum: PHP PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is **especially** suited for web development and can be embedded into HTML. # Getting Started with PHP for Web As PHP is a server langauge it runs on the server. PHP can be used dynamically create HTML from scratch. It can also load content from a database and generate HTML code from a database ## Basic Output *index.php* ```php <?php echo 'Hello'; ?> ``` *index.php* ```php <?php echo '<a href="http://google.com">Google</a>'; ?> ``` ## Understanding Variables A variable in PHP is declared with a **$** (dollar sign). By default, PHP variables don't need to be declared a type, like Java or C. The common "types" in PHP include - String - Integer - Float (floating point numbers - also called double) - Boolean - Array - Object - NULL - Resource ```php <?php //Example of basic variables //Integer $a = 4; //Boolean $b = true; //String $c = "string"; //Array $d = Array( "php", "bob" ) //Object class foo { function do_foo() { echo "Doing foo."; } } $bar = new foo; $bar->do_foo(); ?> ``` If you want to use declartive types in PHP you can enabled **strict types** but you will have to search that up because its not really useful as PHP wasn't designed for types definitions. Also Objects are like any other Object Oriented Programming. This will be discuess more later and not really important currently. ## Concatination, Operators and Accessing Arrays ### Concatination With PHP unlike most other programming languages the concatination uses the **.** (dot) symbol instead of the **+** (addition) symbol. Java Example ```java public class Example { public static void main (String[] args) { System.out.println("I'm " + " a" + " string"); } } ``` PHP Example ```php <?php echo "I'm " . " a" . " string"; ?> ``` ### Operators As for operators they are pretty alike to Java, Python and JavaScript. For more complex math operators you can look up built in functions that PHP gives. ```php <?php $a = 10 + 11; //Division //> 21 $b = 5*5 //Multiplication //> 25 $c = 10/10; //Div //> 1 $d = 1-1; //Sub //> 0 ?> ```` ### Accesing Arrays When you are using an array we ## Understanding GLOBALS (POST, GET, REQUEST, SESSION) Now that you understand the base langauge, you have what I would call events, or global built in variables that PHP and the webserver will give back to the client when the client has submitted that information. ### GET The get variable defined as **$_GET** is an array. But where is the get data specified?????? Well thats in the URL Address! So if we go to this website http://myapplication.com/events?event=1&location=Iceland When we use the var_dump function that built into PHP we will get an array of items with keys paired to its value ```php <?php var_dump($_GET); ?> ``` ``` Array("events" => 1, "location" => "Iceland") ``` But why is this useful? Well as a programmer you can dynmically create links for users which specify this data. You can make really complex GET chains. ## Built in Functions and Objects PHP offers a lot of built in "core" functions, some of the most notable functions include