skip to Main Content

I want to get the id from my url like below

http://localhost/cpanel-ar/stage_one/reports.php?temp=temp_21day

How can GET only the "temp"?

3

Answers


  1. i dont know if i understood but you can use predefined variables using:

    $temp = $_GET['temp'];
    

    but if you are using a framework maybe they already is handle that.

    if you want the ‘temp’ name and you know witch parameters are passed to URL you can use

    array_keys($_GET)[i]
    

    Where i i the index of parameter

    Login or Signup to reply.
  2. why you dont try to use substr function?

    $data = $_GET['temp'];
    echo substr($data,0,4);
    

    its will only catch temp

    Login or Signup to reply.
  3. I assume that you mean this:

    $getVars = array_keys($_GET);
    
    print_r($getVars);
    

    This will return an array with your get parameters.
    for example:
    http:example.com?getparameter=getvalue
    returns:

    Array ( [0] => getparameter )  
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search