RE: [PHP] seeing strange things?
| From: | Ford, Mike [LSS] | Date: | Wed, 09 Jul 2003 10:12:28 +0000 |
| Subject: | RE: [PHP] seeing strange things? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-154514@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Micah Montoy [mailto:montmica@isu.edu]
> Sent: 09 July 2003 01:37
>
> A couple more things and I'll stop bugging everyone. I'm
> trying to get the
> file name of the string. If it includes the extension that's
> fine as well.
> I thought the code below would do this but its not.
>
> $filevalue = str_replace("\\\\", "/", $filevalue);
>
> //get specific file name
> $parts = explode("/",$filevalue);
> $file_name = $parts[count($parts)]; //line 42
>
> Its giving me error:
> Notice: Undefined offset: 6 in
> c:\inetpub\wwwroot\webpage10\example\u_images\act_load_imgs.ph
> p on line 42
This is because count() returns the number of elements in the array, but because the indexes start
at zero the highest offset is count($parts)-1 -- so when you try to access element count($parts),
PHP throws a wobbly.
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211