Skip to content

Instantly share code, notes, and snippets.

@fenric
Created March 6, 2017 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fenric/3a8c6599213cd6dbb34450b1a2492a5e to your computer and use it in GitHub Desktop.
Save fenric/3a8c6599213cd6dbb34450b1a2492a5e to your computer and use it in GitHub Desktop.
<?php
function is($location)
{
$uri = $_SERVER['REQUEST_URI'];
$path = parse_url($uri, PHP_URL_PATH);
$sanitized = addcslashes($location, '\.+?[^]${}=!|:-#');
$expression = str_replace(['(', '*', ')'], ['(?:', '[^/]*', ')?'], $sanitized);
return !! preg_match("#^{$expression}$#u", $path);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment