亲宝软件园·资讯

展开

淘宝URL中ID的提取 对淘宝URL中ID提取的PHP代码

人气:0
想了解对淘宝URL中ID提取的PHP代码的相关内容吗,在本文为您仔细讲解淘宝URL中ID的提取的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:淘宝,URL,ID,下面大家一起来学习吧。

复制代码 代码如下:

<?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;
    }
}
?>

加载全部内容

相关教程
猜你喜欢
用户评论