Switch to full style
PHP examples
Post a reply

check if string start with a specific sub-string in PHP

Mon Jan 07, 2013 3:25 pm

check if string starts with a specific sub-string in PHP
php code
<?php
// check if string starts with a specific sub-string

function startsWith($myString, $needle)
{
return !strncmp($myString, $needle, strlen($needle));
}

$mystr="Bombo anas";
if(startsWith($mystr,"B")==1)
echo "String starts with B";

else
echo "String doesn't start with B";

?>




Post a reply
  Related Posts  to : check if string start with a specific sub-string in PHP
 check if string ends with specific sub-string in php     -  
 Check empty string     -  
 Splitting a String Based on a Found String     -  
 recursive string reversal- reverse string     -  
 String token for string split     -  
 Check the websites hosted at a specific IP     -  
 Pad a string to a certain length with another string     -  
 get string size in c++     -  
 what is string toString()     -  
 get string length in asp     -  

Topic Tags

PHP Strings