Calling all string modification experts

Hey guys,

Can you please help me? I am really bad at string analysis / modification. I even tried looking on Google, but usually still can’t understand how to do what I want to do!

Let’s say you have:


1. http://www.example.com/foo/bar/index.php
2. http://www.example.com/foo/bar/

How can I use PHP to check if the string does or does not have a trailing file at the end? I want to check if it does or does not have a php, or html, or jpg, or ANY file at the end of the URL. May or may not be named index. May be a jpg, html, js, php, asp, file (so I have to disregard extension).

Better yet…
for the following…


$path_parts = pathinfo("/etc/foo/bar/");
$path_parts['dirname'];

Why doesn’t it return /etc/foo/bar/ ?
Instead it returns /etc/foo/
How can I get it to return the /bar/ as well in this case??

Nevermind guys. Sorry.

Here’s what I did:


function getrealpath($url)
{
	$url = pathinfo($url);
	if(strpos($url['basename'],'.') === false){
		return($url["dirname"].'/'.$url["basename"].'/');}

	return($url["dirname"].'/');
}