Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Get URL Parameter and its Value

How do I split the URL and then get its value and store the value on each text input?

URL:

other.php?add_client_verify&f_name=test&l_name=testing&dob_day=03&dob_month=01&dob_year=2009&gender=0&house_no=&street_address=&city=&county=&postcode=&email=&telp=234&mobile=2342&newsletter=1&deposit=1

PHP:

$url = $_SERVER['QUERY_STRING'];
$para = explode("&", $url); 
foreach($para as $key => $value){   
    echo '<input type="text" value="" name="">';    
} 

above code will return:

l_name=testing  
dob_day=3  
doby_month=01  
....

and i tried another method:

$url = $_SERVER['QUERY_STRING'];
$para = explode("&", $url); 
foreach($para as $key => $value){   
    $p = explode("&", $value);
    foreach($p as $key => $val) {
       echo '<input type="text" value="" name="">';
    }   
} 
like image 606
tonoslfx Avatar asked Dec 22 '11 15:12

tonoslfx


People also ask

How can I get current URL parameter in php?

The parameters from a URL string can be retrieved in PHP using parse_url() and parse_str() functions.

What does $_ GET do in PHP?

PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get". $_GET can also collect data sent in the URL. When a user clicks on the link "Test $GET", the parameters "subject" and "web" are sent to "test_get.

How do you access the data sent through the URL with the GET method in PHP?

Read the Data: PHP has $_GET superglobal that accepts all the data from the URL and stores it as an array. Syntax: print_r($_GET); Get data and store in an array with some extra information.


1 Answers

Why not using $_GET global variable?

foreach($_GET as $key => $value)
{  
  // do your thing.
}
like image 53
Lubor Bílek Avatar answered Nov 01 '22 11:11

Lubor Bílek