This is probably going to be pretty basic for anyone that is good with regular expressions. Unfortunately I am not. I have tried, but the only solution I came up with didn't work right and took up a bunch of lines of code to do it.
The language I need to do this in is PHP. I would prefer to do this in preg instead of ereg since ereg is supposed to be depreciated in the next version of PHP.
I want to take a URL and "shrink" it if it is over a certain number of characters.
This is just an example URL that I saw that is too long:
What I want to do is if the URL is over 80 characters I want to try and shrink it down. The above URL should become:
So it would keep the first section and the last section.
If it i still over 80 characters, I'd like for it to then go into the final section, the above would become:
It would go into the final section removing characters until it got it so that the string was 80 characters, including the ellipsis (...).
Any ideas? If you post code that does this, please explain how the code works. I want to learn from this, not just get a block of code that works.
Thanks for any insight that you may provide in advance.