How to get substring after last separator in php?
This function will return the last substring after trimming the string according to the separator passed in.
1. Code:
<?php
function getSubstringAfterLastSeparator($separator, $str){
if (!isset($str) || trim($str) == '') {
return "";
}
$wordArr = explode($separator, $str);
$number = end($wordArr);
return $number;
}
$str = "Soltuts.com is providing PHP tutorials";
$str = getSubstringAfterLastSeparator(" ",$str);
echo($str);
?>
2. Example:
Input:
"Soltuts.com is providing PHP tutorials"
Output:
tutorials