简体   繁体   中英

How to shorten a URL using PHP

guys.

I am trying to work on a solution for shortening urls with php. Currently a hash is a bit too long for a commercial link, and APIs for shortening urls are paid, which is not an option for me. Is there a way to shorten a md5 output or any API that works somewhat like bit.ly?

Thanks a lot.

Require the Package

composer require Kozhinhikkodan/url-short 

Use the namespace and returns 'shortened URL'

# use the package 
use Kozhinhikkodan\UrlShort\UrlShort; 
 
# returns 'shortened URL' 
$UrlShort = new UrlShort(); 
return $UrlShort->short_url($url); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM