Re: Checking if

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux