Blogger Information
Blog 3
fans 0
comment 0
visits 3534
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php处理替换链接参数
Empty的博客
Original
978 people have browsed it

<?php
$url = 'http://www.baidu.com/index.php?m=content&c=index&a=lists&catid=6&area=0&author=0&h=0&region=0&s=1&page=1';

$arr = parse_url($url);
print_r($arr);
$arr_query = convertUrlQuery($arr['query']);

print_r(getUrlQuery($arr_query));

/**
* 将字符串参数变为数组
* @param $query
* @return array array (size=10)
                    'm' => string 'content' (length=7)
                    'c' => string 'index' (length=5)
                    'a' => string 'lists' (length=5)
                    'catid' => string '6' (length=1)
                    'area' => string '0' (length=1)
                    'author' => string '0' (length=1)
                    'h' => string '0' (length=1)
                    'region' => string '0' (length=1)
                    's' => string '1' (length=1)
                    'page' => string '1' (length=1)
*/
function convertUrlQuery($query)
{
    $queryParts = explode('&', $query);
    $params = array();
    foreach ($queryParts as $param) {
        $item = explode('=', $param);
        $params[$item[0]] = $item[1];
    }
    return $params;
}

/**
* 将参数变为字符串
* @param $array_query
* @return string string 'm=content&c=index&a=lists&catid=6&area=0&author=0&h=0&region=0&s=1&page=1' (length=73)
*/
function getUrlQuery($array_query)
{
    $tmp = array();
    foreach($array_query as $k=>$param)
    {
        if($k=='ali_trackid'){
            $tmp[] = $k.'='.'2:mm_58345187_23388879_77836075:1495808287_3k6_1652169695';
        }else{
            $tmp[] = $k.'='.$param;
        }

    }
    $params = implode('&',$tmp);
    return $params;
}

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post