directory wildcard for including files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
osxxso
Forum Newbie
Posts: 2
Joined: Sun Apr 08, 2012 6:09 pm

directory wildcard for including files

Post 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!
osxxso
Forum Newbie
Posts: 2
Joined: Sun Apr 08, 2012 6:09 pm

Re: directory wildcard for including files

Post by osxxso »

This works...

Code: Select all

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