Fasaha mai tasowa

PHP: Amfani da Is.gd API zuwa Rage URL

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.

Douglas Karr

Douglas Karr shine wanda ya kafa Martech Zone da ƙwararren ƙwararren masani akan canjin dijital. Douglas ya taimaka fara farawa MarTech da dama masu nasara, ya taimaka a cikin ƙwazo na sama da dala biliyan 5 a cikin saye da saka hannun jari na Martech, kuma ya ci gaba da ƙaddamar da nasa dandamali da sabis. Shi ne co-kafa Highbridge, Kamfanin tuntuɓar canji na dijital. Douglas kuma marubuci ne da aka buga na jagorar Dummie da kuma littafin jagoranci na kasuwanci.

daya Comment

Me kuke tunani?

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

shafi Articles