Jeffro Posted August 3, 2011 Share Posted August 3, 2011 I need a php fix that says... No matter what the phrase (because it will always be different), delete the last 3 dashes and the last 3 words. This-is-an-example-sentence-right-here would output: This-is-an-example Possible.. or too tricky? Thanks! Quote Link to comment Share on other sites More sharing options...
Alex Posted August 3, 2011 Share Posted August 3, 2011 You don't need regex for this. You can just use explode: $str = 'This-is-an-example-sentence-right-here'; echo implode('-', explode('-', $str, -3)); Note: This requires PHP 5.1.0 (when support for a negative limit parameter was added). Quote Link to comment Share on other sites More sharing options...
Jeffro Posted August 3, 2011 Author Share Posted August 3, 2011 You don't need regex for this. You can just use explode: $str = 'This-is-an-example-sentence-right-here'; echo implode('-', explode('-', $str, -3)); Note: This requires PHP 5.1.0 (when support for a negative limit parameter was added). That could not have worked any better. I expected a much longer solution. THANK YOU!!! 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.