Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing last part of string divided by a colon

Tags:

string

php

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.

like image 905
Harry Beasant Avatar asked Sep 08 '12 21:09

Harry Beasant


1 Answers

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

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

like image 97
Martin Avatar answered Sep 22 '22 05:09

Martin