php string function to get substring before the last occurrence of a character

$string = "Hello World Again";
echo substr($string, 0, strrpos( $string, ' ') ); //Hello World

If the character isn’t found, nothing is echoed

Leave a Comment