say my URL is:
someplace.com/products.php?page=12
How can I then get the information regarding page being equal to 12?
asked Aug 1, 2011 at 17:31
jmasterxjmasterx
51.1k93 gold badges300 silver badges537 bronze badges
All the GET
variables are put into a superglobal array: $_GET
. You can access the value of 'page' with $_GET['page']
.
For more information see PHP.Net: $_GET
Nightfirecat
11.2k6 gold badges33 silver badges50 bronze badges
answered Aug 1, 2011 at 17:33
It's not clear whether you're talking about finding the value of page
from within the PHP page handling that URL, or if you have a string containing the URL and you want to parse the page
parameter.
If you're talking about accessing query string parameters from within products.php
, you can use the super-global $_GET
, which is an associative array of all the query string
parameters passed to your script:
echo $_GET['page']; // 12
If you're talking about a URL stored in a string, you can parse_url
to get the parts of the URL, followed by parse_str
to parse the query
portion:
$url = "someplace.com/products.php?page=12";
$parts = parse_url[$url];
$output = [];
parse_str[$parts['query'], $output];
echo $output['page']; // 12
Mike Q
5,9884 gold badges49 silver badges57 bronze badges
answered Aug 1, 2011 at 17:33
user229044♦user229044
225k40 gold badges323 silver badges333 bronze badges
0
Please check below code to get data from particular URL
Farhad
6,2288 gold badges41 silver badges65 bronze badges
answered Feb 2, 2018 at 10:12
You can use superglobal variable
$_GET
. In this case $_GET['page']
.
answered Aug 1, 2011 at 17:34
Ondrej SlintákOndrej Slinták
30.7k20 gold badges92 silver badges125 bronze badges
Thats done with the variable $_GET['page']
[this gives you the value of page, in this case 12]
Nightfirecat
11.2k6 gold badges33 silver badges50 bronze badges
answered Aug 1, 2011 at 17:33
ManuelManuel
9,9135 gold badges40 silver badges60 bronze badges
$_GET['page']
You have to use $_GET to grab query info.
answered Aug 1, 2011 at 17:33
ngenngen
8,6082 gold badges18 silver badges15 bronze badges
0
Use $_GET['page'] OR $_REQUEST['page']
answered Mar 11, 2019 at 10:08