Php simple short URL (short URL) restoration method (available for test), php Restoration
This example describes how to restore a short URL in php. We will share this with you for your reference. The details are as follows:
Here to help the House of http://www.bkjia.com short Web site http://t.cn/heehwkfor Example run effect as below:
The Code is as follows:
<? Php $ info1 = 'Dear! You cannot resolve such short URLs. '; $ Info2 =' Dear! Failed to parse the URL. Please try again. '; $ Info3 =' <br/> <B> <a href = "'; $ info4 = '"target =" _ blank "> visit now >></a> </B>'; $ info5 = 'Dear! It is not a short URL or is invalid. '; Function unshort ($ url) {global $ info1, $ info2, $ info3, $ info4; $ curl = curl_init (); curl_setopt ($ curl, CURLOPT_URL, $ url ); curl_setopt ($ curl, expires, 1); curl_setopt ($ curl, CURLOPT_USERAGENT, 'mozilla/8.0 (compatible; MSIE 8.0; Windows 7'); curl_setopt ($ curl, CURLOPT_HEADER, 1); curl_setopt ($ curl, CURLOPT_NOBODY, 0); curl_setopt ($ curl, CURLOPT_TIMEOUT, 15); curl_setopt ($ curl, CURLOPT_E NCODING, 'gzip '); $ data = curl_exec ($ curl); if (! Empty ($ data) {$ message = curl_getinfo ($ curl); curl_close ($ curl); $ status = $ message ['HTTP _ Code']; if ($ status = '000000' | $ status = '000000') {$ UrlHeader = (get_headers ($ url, 1 )); $ unurl = $ UrlHeader [Location]; if (is_array ($ unurl) {$ unurl = $ unurl [0]; $ unurl. = $ info3. $ unurl. $ info4; return $ unurl;} else {$ unurl. = $ info3. $ unurl. $ info4; return $ unurl;} return $ info1;} return $ info2;} function ad Funshort ($ url) {global $ info3, $ info4, $ info5; $ c = file_get_contents ($ url); $ p = "/url = '(. *) ';/isU "; preg_match ($ p, $ c, $ content); $ unurl = $ content [1]; if ($ unurl = '') {return $ info5;} else {$ unurl. = $ info3. $ unurl. $ info4; return $ unurl ;}}?> <Form action = "" method = "post"> short URL: <input type = "text" name = "turl" class = "inurl" size = "26"/> <input type = "hidden" name = "url_done" value = "done "/> <input type =" submit "value =" submit "class =" suburl "/> </form> <div id =" trurl "> <? Php $ turl = $ _ POST ['twurl']? $ _ POST ['twurl']: ""; $ url_done =$ _ POST ['url _ done']? $ _ POST ['url _ done']: ""; if ($ url_done = 'done') {$ http = substr ($ turl ); if ($ http! = 'HTTP: // '& $ http! = 'Https: // ') {$ turl = 'HTTP ://'. $ turl;} $ tturl = substr ($ turl, 0, 11); if ($ tturl = 'HTTP: // adf. ') {$ longurl = adfunshort ($ turl);} else {$ longurl = unshort ($ turl);} echo "short URL ". $ turl. "The actual URL is: <br/> $ longurl" ;}?>
In addition,This site also provides a short URL generation tool. The specific links are as follows:
Http://tools.jb51.net/password/dwzcreate