How to check if a string starts and ends with specific character in PHP

1 Answer

0 votes
$str = "#php#"; 
     
if ($str[0] === '#' && $str[strlen($str) - 1] === '#') {
    echo "yes";
}
else {
    echo "no";
}

     

 
/*
run:
      
yes
     
*/

 



answered Apr 18, 2019 by avibootz

Related questions

...