Page 1 of 1

directory wildcard for including files

Posted: Sun Apr 08, 2012 6:46 pm
by osxxso
I'm using if else statements to include specific files according to directory but I also want to be able to use a wildcard so that every directory above the current one includes the same file.

i.e.
http://www.domain.com/dir1/ // includes leftpane_for_dir1.php
http://www.domain.com/dir1/* // any directory above also includes leftpane_for_dir1.php
http://www.domain.com/dir2/ // includes leftpane_for_dir2.php
http://www.domain.com/dir2/* // any directory above also includes leftpane_for_dir2.php

This is what I have so far.

Code: Select all

<?php 

	$uri = $_SERVER['REQUEST_URI'];

	// Handle Left Pane	
	if ($uri == '/dir1/') 
	{
		// dir1
		require_once $leftpane_for_dir1;
	}
	elseif ($uri == '/dir2/') 
	{
		// dir2
		require_once $leftpane_for_dir2;
	}
	else
	{
		// Generic
		require_once $leftpane;
	}

?>
Any help is appreciated. Thanks!

Re: directory wildcard for including files

Posted: Sun Apr 08, 2012 7:19 pm
by osxxso
This works...

Code: Select all

if (strpos($uri, "/dir1/") !== FALSE) 
	{
		// dir1
		require_once $leftpane_for_dir1;
	}