PHP Parse URL From Current URL

前端 未结 6 994
被撕碎了的回忆
被撕碎了的回忆 2021-01-29 05:38

I am trying to parse url and extract value from it .My url value is www.mysite.com/register/?referredby=admin. I want to get value admin from this url.

6条回答
  •  無奈伤痛
    2021-01-29 06:01

    Is not a really clean solution, but you can try something like:

    $url = "MYURL";
    $parse = parse_url($url);
    parse_str($parse['query']);
    
    echo $referredby; // same name of the get param (see parse_str doc)
    

    PHP.net: Warning

    Using this function without the result parameter is highly DISCOURAGED and DEPRECATED as of PHP 7.2.

    Dynamically setting variables in function's scope suffers from exactly same problems as register_globals.

    Read section on security of Using Register Globals explaining why it is dangerous.

提交回复
热议问题