
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP $_GET
Introduction
$_GET is an associative array of variables passed to the current script via query string appended to URL of HTTP request. Note that the array is populated by all requests with a query string in addition to GET requests.
$HTTP_GET_VARS contains the same initial information, but has been deprecated
By default, client browser sends a request for URL on the server by HTTP GET method. A query string attached to URL may contain key=value pairs concatenated by & symbol. The $_GET associative array stores these key value pairs
Assuming that the URL in browser is http://localhost/testscript.php?name=xyz&age=20
Example
<?php echo "Name : " . $_GET["name"] . "<br>"; echo "Age : " . $_GET["age"]; ?>
Output
This will produce following result −
Name : xyz Age : 20
In following example, htmlspecialchars() function is used to convert characters in HTML entities.
Character | Replacement |
---|---|
< (less than) | < |
' (single quote) | ' or ' |
" (double quote) | " |
& (ampersand) | & |
> (greater than) | > |
Assuming that the URL in browser is http://localhost/testscript.php?name=xyz&age=20
Example
<?php echo "Name: " . htmlspecialchars($_GET["name"]) . "<br>"; echo "age: " . htmlspecialchars($_GET["age"]) . "<br>"; ?>
Output
This will produce following result −
Name : xyz Age : 20
- Related Articles
- PHP php://
- Upload file with php to another php server
- PHP Generators.
- PHP Overloading
- PHP Traits
- PHP $GLOBALS
- PHP $_SERVER
- PHP superglobals
- PHP References
- PHP Constants
- PHP Expressions
- PHP Tags
- PHP Iterables
- PHP NULL
- PHP Objects.
