John Davidson

get - Storing a parameter in an array in a URL as a variable in PHP

0 comments
Message:


Here is the URL:


https://all.burgbuilderdev.com/results-page/?address%5B0%5D=Milwaukee%2C%20WI%2053207&post%5B0%5D=project&distance=30&units=imperial&per_page=5&lat=42.971207&lng=-87.904057&form=2&action=fs

I realize it is in an array but I can't figure out how to target it and store it as a variable. I'm certain this is dumb (I'm a beginner with PHP) but I've tried things like:


$address = $_GET['address'];

and

$address = $_GET ['address%5B0%5D'];

and

$address = $_GET['address[0]'];


to no avail.. Thanks for stopping by!



My Answer:
To store the parameter "address[0]" in an array as a variable in PHP, you can use the following code:

php
$url = "https://all.burgbuilderdev.com/results-page/?address[0]=Milwaukee, WI 53207";

// Parse the URL to get the query string
$queryString = parse_url($url, PHP_URL_QUERY);

// Parse the query string to get the parameters
parse_str($queryString, $params);

// Store the "address[0]" parameter in an array as a variable
$address = $params['address'][0];

// Output the variable
echo $address;


This code will extract the "address[0]" parameter from the URL and store it in the variable $address. You can then use this variable in your PHP code as needed.

Rate this post

4 of 5 based on 7486 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us