The PHP Hypertext Preprocessor (PHP) is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications. This tutorial helps you to build your base with PHP.
PHP started out as a small open source project that evolved as more and more people found out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994.
Find a web host with PHP and MySQL support. Install a web server on your own PC, and then install PHP and MySQL.
The PHP syntax and semantics are the format (syntax) and the related meanings (semantics) of the text and symbols in the PHP programming language. They form a set of rules that define how a PHP program can be written and interpreted.
PHP Variables Scope. In PHP, variables can be declared anywhere in the script. The scope of a variable is the part of the script where the variable can be referenced/used.
They are both used to output data to the screen. The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.
PHP Data Types
String, Integer, Float (floating point numbers - also called double) Boolean.
Strings. Advertisements. They are sequences of characters, like "PHP supports string operations". NOTE − Built-in string functions is given in function reference PHP String Functions.
A constant is an identifier (name) for a simple value. The value cannot be changed during the script. A valid constant name starts with a letter or underscore (no $ sign before the constant name). Note: Unlike variables, constants are automatically global across the entire script.
The PHP assignment operators are used with numeric values to write a value to a variable. The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right. Assignment.
PHP Conditional Statements. ... if...else statement - executes some code if a condition is true and another code if that condition is false. if...elseif....else statement - executes different codes for more than two conditions. switch statement - selects one of many blocks of code to be executed.
The switch statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to.
For loops are the most complex loops in PHP. They behave like their C counterparts. The syntax of a for loop is: for (expr1; expr2; expr3) statement. The first expression ( expr1 ) is evaluated (executed) once unconditionally at the beginning of the loop.
PHP User Defined Functions. Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used repeatedly in a program. A function will not execute immediately when a page loads. A function will be executed by a call to the function.
PHP - Arrays. Advertisements. An array is a data structure that stores one or more similar type of values in a single value. For example if you want to store 100 numbers then instead of defining 100 variables its easy to define an array of 100 length.
When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named "welcome.php". The form data is sent with the HTTP POST method. To display the submitted data you could simply echo all the variables.
This section will be focusing on some advanced PHP topics, which will empower the reader to create dynamic web pages. Superglobals. In the previous chapters the concept of global variable was explained. A global variable is a variable declared at the top of the script outside the function.
MySQL is an open source relational database management system (RDBMS) based on Structured Query Language (SQL). MySQL runs on virtually all platforms, including Linux, UNIX, and Windows.