zoukankan      html  css  js  c++  java
  • php解析url并得到url中的参数

    <?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));
    /**
     * 将字符串参数变为数组
     * @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®ion=0&s=1&page=1' (length=73)
     */
    function getUrlQuery($array_query)
    {
      $tmp = array();
      foreach($array_query as $k=>$param)
      {
        $tmp[] = $k.'='.$param;
      }
      $params = implode('&',$tmp);
      return $params;
    }

  • 相关阅读:
    hadoop之 hadoop日志存放路径
    grpc的数据包监控
    HTTP2 概述
    gRPC的简单Go例子
    win下环境变量的设置
    Go的pprof使用
    graphviz
    学习Golang的步骤建议
    golang 的 sync.WaitGroup
    【转】golang的channel的几种用法
  • 原文地址:https://www.cnblogs.com/zhaoying/p/12628957.html
Copyright © 2011-2022 走看看