|
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]
|