Get the GET variables from a URL String

后端 未结 5 1438
生来不讨喜
生来不讨喜 2020-12-05 11:30

Hey, say I have a url just being passed through my php is there any easy way to get some GET variables that are being passed through it? It\'s not the actual url of the page

5条回答
  •  离开以前
    2020-12-05 12:11

    $href = 'http://www.somesite.com/index.php?url=var&file_id=var&test=var';
    
    $url = parse_url($href);
    print_r($url);
    /* Array
    (
        [scheme] => http
        [host] => www.somesite.com
        [path] => /index.php
        [query] => url=var&file_id=var&test=var
    ) */
    
    $query = array();
    parse_str($url['query'], $query);
    
    print_r($query);
    /* Array
    (
        [url] => var
        [file_id] => var
        [test] => var
    ) */
    

提交回复
热议问题