HTML and CSS Reference
In-Depth Information
Now imagine that your app needs to provide a link to the services page that can be accessed from any web page.
Your first instinct would probably be the following:
$services_uri = $site_uri . $services_link;
However, that variable would have the following value:
http://www.example.org//services/
That second double slash is a problem, and when your URI components are being grabbed from various
locations (the $_SERVER superglobal, app-specific configuration, etc.) it's not unlikely that an unwanted double slash
situation will occur.
Therefore, it's worth writing a function to detect and remove any unwanted double slashes in a given URI. However,
because the protocol—meaning the “ http:// ” part—has two slashes, special care needs to be taken not to break
the URI.
To accomplish this, add the following bold code to index.php:
//-----------------------------------------------------------------------------
// Function declarations
//-----------------------------------------------------------------------------
/**
* Breaks the URI into an array at the slashes
*
* @return array The broken up URI
*/
function parse_uri( )
{
// Removes any subfolders in which the app is installed
$real_uri = preg_replace(
'~^'.APP_FOLDER.'~',
'',
$_SERVER['REQUEST_URI'],
1
);
$uri_array = explode('/', $real_uri);
// If the first element is empty, get rid of it
if (empty($uri_array[0])) {
array_shift($uri_array);
}
// If the last element is empty, get rid of it
if (empty($uri_array[count($uri_array)-1])) {
array_pop($uri_array);
}
return $uri_array;
}
 
Search WWH ::




Custom Search