If I have a URL that is http://www.example.com/sites/dir/index.html, I would want to extract the word \"sites\". I know I have to use regular expressions but for some reason my
Use parse_url to get the path from $_SERVER['REQUEST_URI'] and then you could get the path segments with explode:
$_SERVER['REQUEST_URI']
$_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $segments = explode('/', substr($_SERVER['REQUEST_URI_PATH'], 1)); echo $segments[1];