Harry Beasant Harry Beasant - 1 year ago 60
PHP Question

Removing last part of string divided by a colon

I have a string that looks a little like this,

world:region:bash


It divides folder names, so i can create a path for FTP functions.

However, i need at some points to be able to remove the last part of the string, so, for example

I have this
world:region:bash


I need to get this
world:region


The script wont be able to know what the folder names are, so some how it needs to be able to remove the string after the last colon.

Answer Source
$res=substr($input,0,strrpos($input,':'));

I should probably highlight that strrpos not strpos finds last occurrence of a substring in given string