Yesideez Posted February 12, 2007 Share Posted February 12, 2007 Having some major problems here. preg_match('/^.*\/([^\/\.]*)\.\w{3,4}$/','http://www.mydomain.com/here.php',$filename); echo print_r($filename); This displays: Array ( [0] => http://www.mydomain.com/here.php [1] => here ) 1 As you can see it extracts just the filename "here" into $filename[1] however, if I try this: $str=$_SERVER['HTTP_REFERER']; preg_match('/^.*\/([^\/\.]*)\.\w{3,4}$/',$str,$filename); echo print_r($filename); I get this instead: 1 Basically I'm trying to take any URL no matter whether it starts with ftp or http, regardless of the file extension and how many folders it's nested and only return the name of the file itself. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 12, 2007 Share Posted February 12, 2007 You could try doing an explode on "/", filtering out empty values, and then have a list of accepted file extensions and loop through the array until you find the entry that ends with one of the file extensions, (.php) Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 12, 2007 Author Share Posted February 12, 2007 Found the reason I was getting nothing - I was calling that script directly and not linking to it! Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted February 12, 2007 Share Posted February 12, 2007 <?php $url = 'http://www.foo.com/1/2/3/4/foo.php'; $hash = count_chars($url, 1); echo basename($url) . ' ' . ($hash[ord('/')] - 2); ?> Might be a little faster than regex. Best, Patrick Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.