pods_url_variable
(Since 1.6.2) -- retrieve a GET, POST, SESSION, or URI segment variable
function pods_url_variable($key = 'last', $type = 'uri')
Retrieve the sanitized value from one of the following:
- $_GET
- $_POST
- $_SESSION
- a URI segment
Parameters
| Parameter | Type | Details |
|---|---|---|
| $key | MIXED | the URL segment (when $type = "uri"), OR the variable name |
| $type | STRING | (optional) "uri", "get", "post", or "session" |
The $key Parameter
- When type = "uri":
- $key can be either "first", "last", or an integer
- To get the first URI variable: $key = "first" or $key = 0
- To get the last URI variable: $key = "last" or $key = -1
- To get the 2nd URI variable: $key = 1
- To get the 2nd to last URI variable: $key = -2
- When type = "get", "post", or "session", $key is the variable name
Returns
String, or false.Examples
<?php
/*
Sample URL: http://yoursite.com/us/virginia/alexandria/?thevar=28
*/
// All of these output "alexandria"
echo pods_url_variable();
echo pods_url_variable('last');
echo pods_url_variable(-1);
echo pods_url_variable(2);
// All of these output "us"
echo pods_url_variable('first');
echo pods_url_variable(0);
echo pods_url_variable(-3);
// All of these output "virginia"
echo pods_url_variable(1);
echo pods_url_variable(-2);
// This outputs "28"
echo pods_url_variable('thevar', 'get');
?>
