Reply to Re: [PHP] Checking if

Your name:

Reply:


Posted by Richard Lynch on 10/21/75 11:05

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

[Back to original 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

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация