Re: Getting part of a string...Was protecting a file via php
| From: | Curt Zirzow | Date: | Tue, 16 Sep 2003 15:26:58 +0000 |
| Subject: | Re: Getting part of a string...Was protecting a file via php | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-162755@lists.php.net to get a copy of this message | ||
* Thus wrote Jon Haworth (jon@laughing-buddha.net):
> Hi Steve,
>
> > $pfile = str_replace('get.php?file=','','$file');
> > $p = explode('.', $pfile);
> > // How do I say look at the extension and put it into the switch?
> > $extension = $p;
> > // end of the bit I'm stuck on.
>
> At this point $p is an array rather than a variable, so you'll need to get
> the last element of $p.Try something like this:
>
> $p = explode('.', $pfile);
> $extension = $p[sizeof($p)-1];
I always consider explode to be overkill when a simple:
$extension = substr($pfile, strrpos($pfile, '.')+1);
would do.
Curt
--
"I used to think I was indecisive, but now I'm not so sure."