Ehmm, just compare?
if ('www.mydomain.com/greenapples' === $myurl) {
echo 'green apples!';
}
update
Without further info, I'm not sure if this fits your question, but if you're only interested in the last part of the URL and take into account the possibility that the URL contains a query-string (e.g. ?foo=bar&bar=foo
), try something like this:
// NOTE: $myurl should be INCLUDING 'http://'
$urlPath = parse_url($myurl, PHP_URL_PATH);
// split the elements of the URL
$parts = explode('/', $urlPath);
// get the last 'element' of the path
$lastPart = end($parts);
switch($lastPart) {
case 'greenapples':
echo 'green!';
break;
case 'greenapplesandpears':
echo 'green apples AND pears!';
break;
default:
echo 'Unknown fruit family discovered!';
}
Documentation:
http://www.php.net/manual/en/function.parse-url.php