Jump to content

How do I chop the end off of these phrases?


Jeffro

Recommended Posts

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!

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.