Switch to full style
PHP examples
Post a reply

check if string ends with specific sub-string in php

Mon Jan 07, 2013 3:18 pm

Check if string ends with specific sub string using php
php code
<?php
// check if string ends with specific sub-string
function endsWith($currentString, $target)
{
$length = strlen($target);
if ($length == 0) {
return true;
}

return (substr($currentString, -$length) === $target);
}

$mystr="Test String";
if(endsWith($mystr,"ing"))
echo "String ends with 'ing'";
else
echo "String doesn't end with 'ing'";

?>




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

Topic Tags

PHP Strings