Introduction to PHP (Hypertext Preprocessor PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL , Generic ODBC, etc..) PHP is an open source software (OSS) PHP is free to download and use
What is a PHP File ? PHP files may contain text, HTML tags and scripts PHP files are returned to the browser as plain HTML PHP files have a file extension of ". php ", ".php3", or ". phtml " What Can PHP Do? PHP can generate dynamic page content PHP can create, open, read, write, delete, and close files on the server PHP can collect form data PHP can send and receive cookies PHP can add, delete, modify data in your database PHP can be used to control user-access PHP can encrypt data
PHP Syntax A PHP script can be placed anywhere in the document. A PHP script starts with : <? php And ends with: ?> PHP statements end with a semicolon (;)
PHP Case Sensitivity In PHP, all keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are NOT case-sensitive. In the example below, all three echo statements below are legal (and equal ) However; all variable names are case-sensitive.
Comments A comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read by someone who is looking at the code. In PHP, we use // to make a single-line comment or /* and */ to make a large comment block .
Variables Variables are used for storing values, such as numbers, strings or functions results, so that they can be used many times in a script . All variables in PHP start with a ( $ )sign symbol. The correct way of setting a variable in PHP
A variable starts with the $ sign, followed by the name of the variable A variable name must start with a letter or the underscore character A variable name cannot start with a number A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive ($age and $AGE are two different variables) A variable name should not contain spaces. If a variable name is more than one word, it should be separated with underscore ($ my_string ), or with capitalization ($ myString )
Variable 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. PHP has three different variable scopes: local global static
Global variable A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function: