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 the dirname function like this:
dirname
$dir = dirname($_SERVER['PHP_SELF']); $dirs = explode('/', $dir); echo $dirs[0]; // get first dir