PHP get name of the including file

in For Beginners, PHP Tutorials & News

Someone on site point and I were arguing about how to get the name of the parent file of an included file and put it into a variable, but after I followed what he suggested I came up with this handy function:

Someone on site point pointed to use get_included_files() so I tried it and came up with:
<?php
if (!function_exists('getIncluder')) {
	function getIncluder($showpath=0) {
		$parentPath = get_included_files();
		$parentPath = $parentPath[0];
		if (!$showpath) {
			$parentPath = explode('/',$parentPath);
			return end($parentPath);
		} else {
			return $parentPath;
		}
	}
}
echo getIncluder(false); // show just filename
echo getIncluder(true); // show full path and filename
?>

© 2011, Crackfeed.Com. No reposting authorized.