- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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