PHP: Amfani da Is.gd API zuwa Rage URL

Sanya hotuna 11843590 s

Kawai karanta labarin akan fa'idodi da haɗari na gajarta URLs akan SEOmoz. Ina amfani da API na Is.gd yi wannan tare da Plugin SMS na WordPress cewa na rubuta (a halin yanzu gwadawa da yin kyau!).

aiki doCurlRequest ($ url, $ mai canji, $ darajar) {$ api = $ url. "?". $ canji. "=". $ darajar; $ zaman = curl_init (); curl_setopt ($ zaman, CURLOPT_URL, $ api); curl_setopt ($ zaman, CURLOPT_RETURNTRANSFER, 1); $ data = curl_exec ($ zaman); curl_close ($ zaman); dawo da bayanan $; } aiki doShortenURL ($ longurl) {$ url = "http://is.gd/api.php"; $ canji = "longurl"; $ shorturl = doCurlRequest ($ url, $ canji, $ longurl); dawo da $ shorturl; }

Kuna tsammanin ku mutane zasu iya godiya da ainihin lambar samfurin. Tabbatar maye gurbin funkified quotes wanda sanya wannan a cikin shafin yanar gizo yana karawa. Don amfani, kawai ƙara ayyukan da ke sama zuwa shafin PHP ɗinku sannan aiwatar kamar haka:

doShortenURL ('http://thisis.my/long/url/with?lots=of&data=');

Da alama zan ƙara gwada / kama kama don tabbatar. Wannan lambar tana aiki tare da PHP 5 + tare da kunna ɗakunan karatu na curl. Idan mai masaukin ku bai kunna CURL ba, nemi sabon masauki.

daya comment

  1. 1

Me kuke tunani?

Wannan shafin yana amfani da Akismet don rage spam. Koyi yadda aka sarrafa bayanan bayaninka.