I need some help in PHP to create short urls just like StackOverflow creates when we comment any long URL in comments on a question.
StackOverflow shortens http://www.noupe.com/how-tos/10-ways-to-automatically-manually-backup-mysql-database.html
long url to short urls like this noupe.com/...
I require similar kind of functionality in my application. Can anyone give some idea or code how to do that in PHP?
I tired searching it on StackOverflow but not found any question. I remember I had seen such type of question on SO, but right now I am not able to find it :(
Please help!
Just an outline of a simplistic algorithm.
http://
or https://
at the beginning with str_replace
./
and only keep the first item in the returned array./...
at the end.www.
at the begining with str_replace
.With this found string, naming it [shortURL]
, you compose your anchor:
<a href="[fullURL]">[shortURL]</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With