multiple extension filenames

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

multiple extension filenames

Post by sh33p1985 »

in php
an image file could have the possible extensions .gif .jpg .jpeg, if im searching for a filename how can i make sure it has one of these extensions?

eg if im searching for the image src in a string containing all of the img tag parameters and the image could be one of these three extensions, how can i make sure it checks for all these variations?
thank you for any help
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

uhm... maybe you could search for all of them??
Are you asking how to search through a string??
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

Post by sh33p1985 »

no no, in perl the follow link of code basically will list all .gif .jpg .jpeg

if($file =~ /.*\gif|jpe?g/){

need something similar in php

$image = "image"(then the possible extensions it could have here) to avoid doing multiple or statments
User avatar
angrytuna
Forum Newbie
Posts: 12
Joined: Mon Feb 23, 2004 1:01 am

Post by angrytuna »

if($file =~ /.*\gif|jpe?g/){
Not so good. What if my file is kathie_lee_gifford.png? Don't forget the $ to denote the end of the string when doing regexp searches like that.

That said, you might find the basename function useful, coupled with some creative application of scandir.
User avatar
Pointybeard
Forum Commoner
Posts: 71
Joined: Wed Sep 03, 2003 7:23 pm
Location: Brisbane, AUS
Contact:

Post by Pointybeard »

You could use $array = explode(".", strtolower('FILENAME')) This will give you and array containg each bit of the filename broken up by '.' Then just get the last item in the array $ext = $array[count($array)-1]; Simple way to do it.
Post Reply