Get data from url php

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

Get data from url php

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

Get data from url php

Mike Q

5,9884 gold badges49 silver badges57 bronze badges

answered Aug 1, 2011 at 17:33

user229044user229044

225k40 gold badges323 silver badges333 bronze badges

0

Please check below code to get data from particular URL


Get data from url php

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)

Get data from url php

Nightfirecat

11.2k6 gold badges33 silver badges50 bronze badges

answered Aug 1, 2011 at 17:33

Get data from url php

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

How get data from API URL in PHP?

php // Include Request and Response classes $url = 'https://api.exoclick.com/v2/login'; $params = array( 'api_token' => 'tokenhere' ); // Create a new Request object $request = new Request($url, 'POST', $params); // Send the request $request->send(); // Get the Response object $response = $request->getResponse(); if($ ...

How can I get information from a URL?

How to Access Data From a URL Using Java.
Create a URLConnectionReader class..
Now, create a new URL object and pass the desired URL that we want to access..
Now, using this url object, create a URLConnection object..
Use the InputStreamReader and BufferedReader to read from the URL connection..

How parse URL in PHP?

The parse_url() function is an inbuilt function in PHP which is used to return the components of a URL by parsing it..
It return an associative array if the component parameter is omitted..
It return a string if the component parameter is specified..
It return false, if the parameter is malformed URL..

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

The data sent by GET method can be accessed using QUERY_STRING environment variable. The PHP provides $_GET associative array to access all the sent information using GET method.