All pastes #974387 Raw Edit

Something

public text v1 · immutable
·published 2008-04-06 19:28 UTC
rendered paste body
<?php



	/**

	* BEGIN MESS

	*/

	function removeExt($file)

	{

		if (strpos($file,'.')===false)

		{

			return $file;

		} else {

			return substr($file, 0, strrpos($file,'.'));

		}

	}

	

	function removeUnder($string)

	{

		return str_replace('_',' ', $string);

	}

	

	function removeDir($dir, $path)

	{

		return str_replace($dir, '', $path);

	}

	

	function removeSlash($path)

	{

		return str_replace('/', '', $path);

	}

	

	function safeName($dir, $path)

	{

		return removeExt(removeUnder(removeSlash(removeDir($dir, $path))));

	}

	

	/**

	* END MESS

	*/

	

	function listStuff($dir)

	{

		$array = array();

		if($handle = opendir($dir))

		{

			while(FALSE !== ($file = readdir($handle)))

			{

				if($file != '.' && $file != '..')

				{

					$array[] = $file;

				}

			}

			arsort($array);

			foreach($array as $id => $link)

			{

				$name = safeName($dir, $link);

				echo "<li><a href=\"$dir/$link\" title=\"$name\">$name</a></li>";

			}

		} else {

			echo "<li>There was an error</li>";

		}

	}

	

?>