You can try something like this:
<?php $variable = "world:region:bash"; $colpos = strrpos($variable, ":"); $result = substr($variable, 0, $colpos); echo $result; ?>
Or ... if you create a function using this information, you will get the following:
<?php function StrRemoveLastPart($string, $delimiter) { $lastdelpos = strrpos($string, $delimiter); $result = substr($string, 0, $lastdelpos); return $result; } $variable = "world:region:bash"; $result = StrRemoveLastPart($variable, ":"); ?>
source share