HTML5 and PHP: Syntax, Semantics, and Superglobal Variables
HTML: Markup to differentiate information about content. W3C recommendations for contents and elements. XHTML requires empty elements terminated by a trailing slash. In HTML5, the trailing slash in empty elements is optional. Semantic advantages include maintainability, performance, accessibility, and Search Engine Optimization. HTML5 does not require the use of the <html>, <head>, and <body> tags.
PHP
PHP code is enclosed within <?php ?> tags.
Comments:
#/* *///
Variables:
Variables are prefixed with $. Types include boolean, integer, float, string, array, and object.
Constants:
Constants are defined using define(_, _).
String Concatenation:
Strings are appended using . (dot).
Control Structures:
if else if elseswitch() case x:
Functions:
Functions are defined as function name(): string {}. Functions can have default values. Parameters can be passed by reference using &. By default, variables have function scope. Variables in the main scope cannot be accessed within functions unless declared as global.
Arrays:
Arrays can be defined using array(,,,) or [,,,]. All arrays are associative (0=>x, 1=>y). Other keys can also be used.
Iterating Through Arrays:
- Iterating through values:
foreach ($forecast as $value){} - Iterating through keys and values:
foreach ($forecast as $key => $value)
Superglobal Variables:
$GLOBALS: Array for storing data that needs superglobal scope$_COOKIES: Array of cookie data passed to page via HTTP request$_ENV: Array of server environment data$_FILES: Array of file items uploaded to the server$_GET: Array of query string data passed to the server via the URL$_POST: Array of query string data passed to the server via the HTTP header$_REQUEST: Array containing the contents of$_GET,$_POST, and$_COOKIES$_SESSION: Array that contains session data$_SERVER: Array containing information about the request and the server
Example:
if ($_SERVER["REQUEST_METHOD"] == "POST") { if ( isset($_POST["uname"]) … }
HTML: Markup to differentiate information about content. W3C recommendations for contents and elements. XHTML requires empty elements terminated by a trailing slash. In HTML5, the trailing slash in empty elements is optional. Semantic advantages include maintainability, performance, accessibility, and Search Engine Optimization. HTML5 does not require the use of the <html>, <head>, and <body> tags.
PHP
PHP code is enclosed within <?php ?> tags.
Comments:
#/* *///
Variables:
Variables are prefixed with $. Types include boolean, integer, float, string, array, and object.
Constants:
Constants are defined using define(_, _).
String Concatenation:
Strings are appended using . (dot).
Control Structures:
if else if elseswitch() case x:
Functions:
Functions are defined as function name(): string {}. Functions can have default values. Parameters can be passed by reference using &. By default, variables have function scope. Variables in the main scope cannot be accessed within functions unless declared as global.
Arrays:
Arrays can be defined using array(,,,) or [,,,]. All arrays are associative (0=>x, 1=>y). Other keys can also be used.
Iterating Through Arrays:
- Iterating through values:
foreach ($forecast as $value){} - Iterating through keys and values:
foreach ($forecast as $key => $value)
Superglobal Variables:
$GLOBALS: Array for storing data that needs superglobal scope$_COOKIES: Array of cookie data passed to page via HTTP request$_ENV: Array of server environment data$_FILES: Array of file items uploaded to the server$_GET: Array of query string data passed to the server via the URL$_POST: Array of query string data passed to the server via the HTTP header$_REQUEST: Array containing the contents of$_GET,$_POST, and$_COOKIES$_SESSION: Array that contains session data$_SERVER: Array containing information about the request and the server
Example:
if ($_SERVER["REQUEST_METHOD"] == "POST") { if ( isset($_POST["uname"]) … }
HTML: Markup to differentiate information about content. W3C recommendations for contents and elements. XHTML requires empty elements terminated by a trailing slash. In HTML5, the trailing slash in empty elements is optional. Semantic advantages include maintainability, performance, accessibility, and Search Engine Optimization. HTML5 does not require the use of the <html>, <head>, and <body> tags.
PHP
PHP code is enclosed within <?php ?> tags.
Comments:
#/* *///
Variables:
Variables are prefixed with $. Types include boolean, integer, float, string, array, and object.
Constants:
Constants are defined using define(_, _).
String Concatenation:
Strings are appended using . (dot).
Control Structures:
if else if elseswitch() case x:
Functions:
Functions are defined as function name(): string {}. Functions can have default values. Parameters can be passed by reference using &. By default, variables have function scope. Variables in the main scope cannot be accessed within functions unless declared as global.
Arrays:
Arrays can be defined using array(,,,) or [,,,]. All arrays are associative (0=>x, 1=>y). Other keys can also be used.
Iterating Through Arrays:
- Iterating through values:
foreach ($forecast as $value){} - Iterating through keys and values:
foreach ($forecast as $key => $value)
Superglobal Variables:
$GLOBALS: Array for storing data that needs superglobal scope$_COOKIES: Array of cookie data passed to page via HTTP request$_ENV: Array of server environment data$_FILES: Array of file items uploaded to the server$_GET: Array of query string data passed to the server via the URL$_POST: Array of query string data passed to the server via the HTTP header$_REQUEST: Array containing the contents of$_GET,$_POST, and$_COOKIES$_SESSION: Array that contains session data$_SERVER: Array containing information about the request and the server
Example:
if ($_SERVER["REQUEST_METHOD"] == "POST") { if ( isset($_POST["uname"]) … }
HTML: Markup to differentiate information about content. W3C recommendations for contents and elements. XHTML requires empty elements terminated by a trailing slash. In HTML5, the trailing slash in empty elements is optional. Semantic advantages include maintainability, performance, accessibility, and Search Engine Optimization. HTML5 does not require the use of the <html>, <head>, and <body> tags.
PHP
PHP code is enclosed within <?php ?> tags.
Comments:
#/* *///
Variables:
Variables are prefixed with $. Types include boolean, integer, float, string, array, and object.
Constants:
Constants are defined using define(_, _).
String Concatenation:
Strings are appended using . (dot).
Control Structures:
if else if elseswitch() case x:
Functions:
Functions are defined as function name(): string {}. Functions can have default values. Parameters can be passed by reference using &. By default, variables have function scope. Variables in the main scope cannot be accessed within functions unless declared as global.
Arrays:
Arrays can be defined using array(,,,) or [,,,]. All arrays are associative (0=>x, 1=>y). Other keys can also be used.
Iterating Through Arrays:
- Iterating through values:
foreach ($forecast as $value){} - Iterating through keys and values:
foreach ($forecast as $key => $value)
Superglobal Variables:
$GLOBALS: Array for storing data that needs superglobal scope$_COOKIES: Array of cookie data passed to page via HTTP request$_ENV: Array of server environment data$_FILES: Array of file items uploaded to the server$_GET: Array of query string data passed to the server via the URL$_POST: Array of query string data passed to the server via the HTTP header$_REQUEST: Array containing the contents of$_GET,$_POST, and$_COOKIES$_SESSION: Array that contains session data$_SERVER: Array containing information about the request and the server
Example:
if ($_SERVER["REQUEST_METHOD"] == "POST") { if ( isset($_POST["uname"]) … }
