Created
August 9, 2019 09:11
-
-
Save PatricNox/4805b84e4d83552ab48c9ddf97beadbc to your computer and use it in GitHub Desktop.
PHP function that removes the last part of a string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Remove the last part of a string. | |
* | |
* This function removes the last part of a string, conditioned on spaces | |
* inbetween the parts. Like words, in a sentence. | |
* | |
* @param String $string The string. | |
**/ | |
function str_remove_lastpart($string) { | |
$string_parts = explode(' ',$string); | |
unset($string_parts[count($string_parts)-1]); | |
return implode(' ',$string_parts); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment