Get URL query string parameters

前端 未结 11 1435
长情又很酷
长情又很酷 2020-11-22 17:41

What is the \"less code needed\" way to get parameters from a URL query string which is formatted like the following?

www.mysite.com/category/subcateg

11条回答
  •  失恋的感觉
    2020-11-22 17:56

    Programming Language: PHP

    // Inintialize URL to the variable 
    $url = 'https://www.youtube.com/watch?v=qnMxsGeDz90'; 
    
    // Use parse_url() function to parse the URL 
    // and return an associative array which 
    // contains its various components 
    $url_components = parse_url($url); 
    
    // Use parse_str() function to parse the 
    // string passed via URL 
    parse_str($url_components['query'], $params); 
    
    // Display result 
    echo 'v parameter value is '.$params['v'];
    

    This worked for me. I hope, it will also help you :)

提交回复
热议问题