PHP parses the URL and obtains the parameters in the URL and gets the URL parameters

Source: Internet
Author: User
Tags explode

<?PHP$url= ' Http://www.baidu.com/index.php?m=content&c=index&a=lists&catid=6&area=0&author=0&h=0 ®ion=0&s=1&page=1 ';$arr=Parse_url($url);Var_dump($arr);$arr _query= Converturlquery ($arr[' Query ']);Var_dump($arr _query);Var_dump(Geturlquery ($arr _query));/** * Change string parameter to array * @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 ' (lengt h=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)*/functionConverturlquery ($query){  $queryParts=Explode(' & ',$query); $params=Array(); foreach($queryParts  as $param) {    $item=Explode(' = ',$param); $params[$item[0]] =$item[1]; }  return $params;}/** * Change parameter to String * @param $array _query * @return String ' m=content&c=index&a=lists&catid=6&area=0 &author=0&h=0®ion=0&s=1&page=1 ' (length=73)*/functionGeturlquery ($array _query){  $tmp=Array(); foreach($array _query  as $k=$param)  {    $tmp[] =$k.‘ = '.$param; }  $params=implode(' & ',$tmp); return $params;}

Https://www.jb51.net/article/73900.htm

PHP parses the URL and obtains the parameters in the URL and gets the URL parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.