mme Posted August 22, 2010 Share Posted August 22, 2010 Hi, I have a dynamic variable like this: /def/g/qaz/pol/cxz/cba/abc I only wish to keep this: /def/g/qaz/pol/cxz How would I do this? Thanks, - mme Link to comment https://forums.phpfreaks.com/topic/211410-root-path/ Share on other sites More sharing options...
Pikachu2000 Posted August 22, 2010 Share Posted August 22, 2010 Huh? Can you elaborate a bit, perhaps? Link to comment https://forums.phpfreaks.com/topic/211410-root-path/#findComment-1102278 Share on other sites More sharing options...
mme Posted August 22, 2010 Author Share Posted August 22, 2010 I have a random string with a value of: /def/g/qaz/pol/cxz/cba/abc Now I wish to remove /cba/abc from the end. Link to comment https://forums.phpfreaks.com/topic/211410-root-path/#findComment-1102281 Share on other sites More sharing options...
Pikachu2000 Posted August 22, 2010 Share Posted August 22, 2010 Is it always going to be the same number of string 'parts' removed, or kept? Link to comment https://forums.phpfreaks.com/topic/211410-root-path/#findComment-1102282 Share on other sites More sharing options...
mme Posted August 22, 2010 Author Share Posted August 22, 2010 Is it always going to be the same number of string 'parts' removed, or kept? Yes the same 'parts' Link to comment https://forums.phpfreaks.com/topic/211410-root-path/#findComment-1102286 Share on other sites More sharing options...
Pikachu2000 Posted August 22, 2010 Share Posted August 22, 2010 So which one is it? Always keep the first 4, or always strip the last 2? We're not mind readers, you know. Link to comment https://forums.phpfreaks.com/topic/211410-root-path/#findComment-1102367 Share on other sites More sharing options...
mme Posted August 23, 2010 Author Share Posted August 23, 2010 So which one is it? Always keep the first 4, or always strip the last 2? We're not mind readers, you know. Sorry I misunderstood your question, Always strip the last 2. Thanks, Link to comment https://forums.phpfreaks.com/topic/211410-root-path/#findComment-1102632 Share on other sites More sharing options...
Daniel0 Posted August 23, 2010 Share Posted August 23, 2010 $str = '/def/g/qaz/pol/cxz/cba/abc'; echo preg_replace('#(?:/[^/]+){2}$#', '', $str); Link to comment https://forums.phpfreaks.com/topic/211410-root-path/#findComment-1102639 Share on other sites More sharing options...
mme Posted August 23, 2010 Author Share Posted August 23, 2010 $str = '/def/g/qaz/pol/cxz/cba/abc'; echo preg_replace('#(?:/[^/]+){2}$#', '', $str); Thanks so much! All solved now Link to comment https://forums.phpfreaks.com/topic/211410-root-path/#findComment-1102655 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.