程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> 對淘寶URL中ID提取的PHP代碼

對淘寶URL中ID提取的PHP代碼

編輯:PHP綜合

復制代碼 代碼如下:
<?php
$taobao = 'taobao.com';
$tmall = 'tmall.com';
$guojitmall = 'tmall.hk';
$juhuasuan = 'ju.taobao.com';

/*
取寶貝的id

休閒e族

*/
function quid($strurl) {
    $strurl = strtolower ( $strurl );
    if (strpos ( $strurl, 'id' ) !== false) {
        $arr = explode ( '?', $strurl );
        $arr = explode ( '&', $arr [1] );
        $NO = 0;
        foreach ( $arr as $k => $v ) {
            if (is_string ( $v )) {
                //判斷是否含有id
                if (strpos ( $v, 'id' ) !== false) {
                    //處理含有item或者num項 返還id數
                    if (strpos ( $v, 'item' ) !== false || strpos ( $v, 'num' ) !== false) {
                        //echo $v,'<br/>';
                        $i = strrpos ( $v, '=' );
                        $str = substr ( $v, $i + 1 );
                        if (is_numeric ( $str )) {
                            return $NO = $str;
                        }
                    } else {
                        //echo $v,'<br/>';
                        $i = strrpos ( $v, '=' );
                        $str = substr ( $v, $i + 1 );
                        $x = strlen ( $str );
                        if (is_numeric ( $str )) {
                            if ($x ==11) {
                                $NO = $str;
                            } else if ($NO == 0 || ($x > 9 && $x < 11)) {
                                $NO = $str;
                            }
                        }
                    }
                }
            }
        }
        return $NO;
    }
}
?>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved