Many thanks - just what I was looking for!
Cheers Russell -- ----------------------------------- Russell Curtis M +44 (0) 7796268780 www.russellcurtis.com www.buildingdetails.co.uk "Ewout" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > ----- Original Message ----- > From: "Russell Curtis" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Wednesday, July 07, 2004 12:24 PM > Subject: [PHP] Using split to establish extension of file > > > > I'm trying to use the split function to identify the extension of an > > uploaded file: > > > > $file_name = $_FILES['userfile']['name']; > > $pieces = explode(".", $file_name); > > $file_extension = $pieces[1]; // piece2 > > > > Which will work, providing that the uploaded file only has one full-stop > in > > the name (so 'thisfile.pdf' will return 'pdf' as the $file_extension, for > > example.) > > > > However, there is a chance that someone will try and upload a file which > has > > more than one full-stop in it (eg. 'this.file.pdf') which will of course > > return 'file' as the variable $file_extension. > > > > My question is, is there any way to determine what the *last* result of > the > > array is rather than working from the first? > > > > This may be a basic question, but I'm a newbie; apologies in advance if > this > > is a simple one. I'm using PHP4, BTW, if that makes a difference. > > You can get the last element of an array using the 'array_pop' function: > > $last = array_pop($pieces); > > see http://www.php.net/manual/en/function.array-pop.php for details > > > > regards, > Ewout -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php