php - Remove part of string after third occurrence of certain character -


i have special case have whole range of different strings in array.

what need remove last part of string @ third occurrence of /.

example:

accessories / mens accessories / bags wallets / messenger bags /

so here want remove: messenger bags /

how possible php - remember have lot of different strings! can't take position it's different each time.

//here have 4 elements     $parts = explode ('/', $string);  //this glue first 3 elements list ($first, $second, $third) = $parts;  //here can see desired result var_dump (implode ('/',array($first, $second, $third))); 

output

string 'accessories / mens accessories / bags wallets ' (length=46) 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -