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 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 22, 2010 Share Posted August 22, 2010 Huh? Can you elaborate a bit, perhaps? Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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' Quote Link to comment 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. Quote Link to comment 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, Quote Link to comment 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); Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.