Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is this possible with Regular Expressions? 2

Status
Not open for further replies.

rye8261

Technical User
Jul 6, 2003
359
0
0
US
I've never used regular expressions and I'm trying to learn them right now. I have one question before I invest a lot of time on them as this is all I'm trying to do with them.

Is is possible to have a string like this: "Images/Welcome/images/welcome image 19.gif"
An get only this part: "welcome image 19.gif"?

Also, it needs to be able to handle strings like this: "Images/Welcome/Free/images/welcome image 19.gif" and give the same result as above.

So if anyone can give me a simple yes or no I'd appreciate it and if you know how to code it, tips would be very appreciated.

Thanks,

 
yes. but there are much easier ways.

consider this

Code:
$f = "Images/Welcome/images/welcome image 19.gif"
$_f = explode ('/'. $f);
print_r($_f);
the value you want will always be in the last array element
Code:
echo $_f[count($_f) -1];

alternatively you could use the built in functions within php: basename() and pathinfo();

basename() will return just the file name part of the path. pathinfo will return an associative array of information about the whole path, including tha file.
and
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top