FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Good code or bad code?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Good code or bad code? [message #170190 is a reply to message #170185] Sun, 17 October 2010 13:25 Go to previous messageGo to previous message
MikeB is currently offline  MikeB
Messages: 65
Registered: September 2010
Karma:
Member
Hamish Campbell wrote:
> On Oct 17, 5:20 pm, MikeB<mpbr...@gmail.com> wrote:
>> I'm mostly playing with PHP to get a feeling for coding in it.
>>
>> So as part of all this URI/URL/redirect stuff I spent some time looking
>> at the contents of $_SERVER and I came up with this code to find the
>> filename of the file I'm invoked from. Now one condition that I wanted
>> to cater for was if the filename had multiple "."s in the name, for
>> instance myfile.inc.php, or something like this.
>>
>> So I came up with this piece of code.
>>
>> $uriParts = explode("/",$_SERVER['REQUEST_URI']);
>> $thisFile = substr(end($uriParts),0,(strlen(end($uriParts))) -
>> (strlen(end($uriParts))- strrpos(end($uriParts),'.')));
>>
>> So I was wondering if that is good code or if I could have written it
>> better, since looking at it it is quite hard to understand.
>
> Have a look at:
>
> <http://nz.php.net/manual/en/function.pathinfo.php>
>
> e.g:
>
> $name = pathinfo($_SERVER['REQUEST_URI'], PATHINFO_FILENAME);
>

Thank you, that is *much* cleaner and more understandable.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: buffering to allow headers in code?
Next Topic: Stats comp.lang.php (last 7 days)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 08:42:45 GMT 2024

Total time taken to generate the page: 0.04217 seconds