Return A Subfolder From URL Using PHP

Ever need to return a subfolder from a URL because the customer had different email addresses for associative subfolders? This seems to come up a lot here at work.

Eric, a co-worker gave me this nice lil snippet.  I needed to capture a subfolder name, not the entire query and filename, so I thought I would share.

$dir = explode('?', $_SERVER['REQUEST_URI']);
$campaignName = explode('/', $dir[0]);
echo $campaignName[1];

So, if I had a URL such as this: http://www.mysite.com/one, this would echo out ‘one‘.
All one would have to do at this point is put in some conditional statement so you could do whatever based on your subfolder.

In a practical application, I needed to determine the subfolder and use different email addresses based on the folder name. With this, I was able to put in an if statement and set the emails appropriately.

Thanks Eric!