Jump to content

[SOLVED] regex


Yesideez

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/38101-solved-regex/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.