Log in

View Full Version : Shortening a URL with preg_replace



qwikad.com
03-31-2015, 01:09 PM
What would be the easiest way to shorten a URL with preg_replace? Let's say a URL looks like this:

http:/ /someurl.com/file_1/something_else/new/file_2.html

I want to reduce it to let's say 30 characters:

http:/ /someurl.com/file_1/some...

Thanks!

Beverleyh
03-31-2015, 01:51 PM
I think there's a little more to it if you still want the link to work ;)

Have a look at this: https://github.com/briancray/PHP-URL-Shortener

qwikad.com
03-31-2015, 04:49 PM
I think there's a little more to it if you still want the link to work ;)

Have a look at this: https://github.com/briancray/PHP-URL-Shortener


Actually, no, I don't want it to work. I just want it for a preview and it doesn't matter if it works or not.

Beverleyh
03-31-2015, 05:00 PM
In that case, why not use substr() http://ca3.php.net/manual/en/function.substr.php