You are here: Re: [PHP] Checking if « PHP « IT news, forums, messages
Re: [PHP] Checking if

Posted by Morten Rψnseth on 09/28/45 11:05

Bruno B B MagalhΓ£es wrote:
> Richard,
>
> my solution right know is:
>
> if(substr($url,-1) != '/')
> {
> $url = $url.'/';
> }
>
> Simple and fast... :)

$url = preg_replace ("|^(.*)/?$|", "\\1/", $url);




>
> Regards,
> Bruno B B Magalhaes
>
> On Jan 12, 2005, at 3:37 PM, Richard Lynch wrote:
>
>> Bruno B B MagalhΓ£es wrote:
>>
>>> how to determine if the last char of a string is a '/'...
>>>
>>> The problem, a webpage can be accessed by www.domain.com/page.php or
>>> www.domain.com/page.php/
>>
>>
>> In addition to the two fine answers posted so far:
>>
>> if ($string[strlen($string)-1] == '/'){
>> echo "It ends in '/'<BR>\n";
>> }
>> else{
>> echo "It does NOT end in '/'<BR>\n";
>> }
>>
>> substr and the above will be fastest, if it matters (probably not). The
>> different in performance between substr and array reference is
>> negligible,
>> I think.
>>
>> preg_match is more flexible if you need to maybe some day figure out the
>> last several letters in weird combinations.
>>
>> substr will be useful if you might some day need more letters, but not in
>> weird combinations.
>>
>> The array usage may be more natural if you are already tearing apart the
>> string character by character in other bits of the same code.
>>
>> YMMV
>>
>> --
>> Like Music?
>> http://l-i-e.com/artists.htm
>>
>>

Cheers,


-Morten

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация