What is the simplest of checking first and last character of a string in php
Wh开发者_Python百科at is the simplest way of checking whether the first letter of a string $str
is 'a'
and the last letter is 'a'
too?
if($str[0] == 'a' && $str[strlen($str) - 1] == 'a') {
//do whatever you wanted
}
if(substr($str, 0,1) == "a" && substr( $str,-1) == "a")
{
// code
}
Or use substr to get the last character:
if($str[0] == 'a' && substr($str,-1) == 'a') {
//do whatever you wanted
}
精彩评论