直接上源碼,一言不合就上源碼 ...
直接上源碼,一言不合就上源碼
<?php
//淘寶客短網址還原鏈接 //unescape 轉碼 function unescape($str) { $ret = ''; $len = strlen($str); for ($i = 0; $i < $len; $i ++) { if ($str[$i] == '%' && $str[$i + 1] == 'u') { $val = hexdec(substr($str, $i + 2, 4)); if ($val < 0x7f) $ret .= chr($val); else if ($val < 0x800) $ret .= chr(0xc0 | ($val >> 6)) . chr(0x80 | ($val & 0x3f)); else $ret .= chr(0xe0 | ($val >> 12)) . chr(0x80 | (($val >> 6) & 0x3f)) . chr(0x80 | ($val & 0x3f)); $i += 5; } else if ($str[$i] == '%') { $ret .= urldecode(substr($str, $i, 3)); $i += 2; } else $ret .= $str[$i]; } return $ret; } //使用curl模擬請求返回得到真實url function geturl($clickurl){ $headers = get_headers($clickurl, TRUE); $tu = $headers['Location']; $eturl = unescape($tu[1]); //獲取完整連接 $u = parse_url($eturl); //得到et的連接 $param = $u['query']; $ref = str_replace('tu=', '', $param); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $ref); curl_setopt($ch, CURLOPT_REFERER, $tu[1]); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_NOBODY,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true); curl_setopt($ch, CURLOPT_MAXREDIRS,2); $out = curl_exec($ch); $dd = curl_getinfo($ch); curl_close($ch); $item_url = $dd['url']; return $item_url; } $res = geturl("http://s.click.taobao.com/xxx"); //這裡輸入淘寶客短連接 print_r($res);
?>