How can i get data from another website in php?

I would recommend using cURL to actually make the call then DOM to parse. The advantage to using DOM is allowing you a little bit of leeway when it comes to changes on the website. The advantage to curl being extended flexibility and the ability to return errors. This will require quite a bit of studying on your part in order to determine the correct values to look for. The below code should get you started:

// Curl
function curl($url, $post=''){


        //cURL options
        $options = array(

            CURLOPT_RETURNTRANSFER => true,     // return web page
            CURLOPT_HEADER         => false,    // don't return headers
            CURLOPT_FOLLOWLOCATION => true,     // follow redirects
            CURLOPT_ENCODING       => "",       // handle all encodings
            CURLOPT_AUTOREFERER    => true,     // set referer on redirect
            CURLOPT_CONNECTTIMEOUT => 500,      // timeout on connect
            CURLOPT_TIMEOUT        => 500,      // timeout on response
            CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
            CURLOPT_SSL_VERIFYHOST => 0,
            CURLOPT_SSL_VERIFYPEER => 0,
            CURLOPT_USERAGENT      => "",
            CURLOPT_COOKIESESSION  => false,
            CURLOPT_COOKIEJAR     => $this->ckfile, // Cookies
            CURLOPT_COOKIEFILE     => $this->ckfile, //Cookies...yum


        );

        //Go go go!
        $ch      = curl_init( $url );
        curl_setopt_array( $ch, $options );

        $output['content'] = curl_exec( $ch );
        $output['err']     = curl_errno( $ch );
        $output['errmsg']  = curl_error( $ch );
        $output['header']  = curl_getinfo( $ch );
        return $output;

    }

Once you have $output, you can parse with DOM. Few ways you can go about it, I recommend XPATH queries

//Create DOM
        $doc = new DOMDocument;
        @$doc->loadHTML($curl['content']);
        $doc->preserveWhiteSpace = false;

$xpath = new DOMXpath($doc);

        $nodeList = $xpath->query("//div[@id='test']"); // I would recommend trying to find an element that contains the currency elements, but has an attribute that will most likely not be changed. IDs work well, sometime div classes also work. Check out http://www.exampledepot.com/egs/org.w3c.dom/xpath_GetElemByText.html

        foreach($nodeList as $node){

            // From here you would want to select the element http://php.net/manual/en/domdocument.getelementsbytagname.php

}

From there you return it. I would instead recommend parsing http://themoneyconverter.com/RSSFeeds.aspx

<?php
$CurlStart = curl_init();
curl_setopt ($CurlStart, CURLOPT_URL, "http://www.gamersfirst.com/warrock/?q=Player&nickname=soldier");
curl_setopt ($CurlStart, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($CurlStart, CURLOPT_REFERER, $url);
curl_setopt ($CurlStart, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; nl; rv:1.9.1.11) Gecko/20100701 Firefox/3.5.11");
curl_setopt ($CurlStart, CURLOPT_HEADER, 1);
curl_setopt ($CurlStart, CURLOPT_FOLLOWLOCATION, true);
$source = curl_exec ($CurlStart);
curl_close ($CurlStart);

$a=preg_match("/>Level:.*.\n.*.>([0-9]*)</",$source,$b);
$Level = $b[1];
echo "Level: $Level";
?>

How can i get data from another website in php?
There are different ways by which values of variables can be passed between pages. One of the ways is to use the URL to pass the values or data. Here the biggest advantage is we can pass data to a different site even running at different servers. Any scripting language like ASP, JSP, PHP or Perl running at receiving end can process and collect the value from the query string or from the URL.

  • Easy to save the URL or bookmark it for frequent use.
  • Copy the URL and send it to a friend to refer.

Here one main concern is the data gets exposed in address bar of the browser and can be easily accessible by using browser history. So it is not a good idea to pass sensitive data like password through the URL to different pages or different sites.


Passing variable with data to different pages


Here is an example of passing data through URL within a site.

<a href='page2.php?id=2489&user=tom'>link to page2</a>
When the above link is clicked, page2.php gets the variables id and user with data 2489 and tom respectively. Here is the code to collect data in PHP.
echo $_GET['id']; // output 2489
echo $_GET['user']; // output tom

The address of page2.php can be replaced with any site name and the same data can be passed to another site running in any server. Like this

Passing data outside

<a href=https://www.sitename.com/index.php?id=2489&user=tom>Link to another site</a>
Demo of passing data through a form
You can see in the above case the values can be posted to another site. Note that after the page name we are using question mark ( ? ) to start the variable data pair and we are separating each variable data pair with one ampersand ( & ) mark.
How can i get data from another website in php?

Submitting form values through GET method

A web form when the method is set to GET method, it submits the values through URL. So we can use one form to generate an URL with variables and data by taking inputs from the users. The form will send the data to a page within the site or outside the site by formatting a query string.
<form method=GET action='https://www.anysite.com/index.php'>
How can i get data from another website in php?

Submitting a form through POST method

By post method of form submission we can send more number or length of data. Sensitive information like password does not get exposed in URL by POST method, so our login forms we should use POST method to submit data. This is how we collect data submitted by POST method in PHP
$id=$_POST['id'];
$password=$_POST['password'];
Difference between GET and POST
issuesGETPOST
Browser History Data remain in Browser History Data Not available in Browser History
Bookmark URL with Data can be bookmarked No data is available in URL to bookmark the page
Data Length Restriction The restriction (of URL ) is applicable No Restriction
cached Can be cached No meaningful caching
Sensitive Data Data like password , pin etc. are exposed through URL so they should not be passed using GET method Better than GET method as data is not exposed through URL

Read more on difference between GET and POST method of form submission

Collecting data submitted by either GET or POST method

If a page is receiving a data which can come in any one of the method GET or POST then how to collect it ? Here we are not sure how to collect the data. So we will use like this.
$id=$_REQUEST['id'];
$password=$_REQUEST['password'];

Every scripting language pages has its own way of receiving the data from the URL

While receiving the data based on the server settings the values will be available to the pages. Here in a server running PHP will have to see the global settings of the server on how to collect the data.
$id=$_GET['id'];
$user=$_GET['user'];
Same way in ASP environment running VB script the data can be collected and assigned like this
Id = Request.QueryString("id")
User = Request.QueryString('user')

Passing data within the site using URL

The same principle is used like above to send the data within the site using URL. A query sting can be formatted with a link or a form can be used with get method to pass variables between pages.

Passing the data between the site through URL

Like above data can be passed to different pages of sites using URL . The best use is directly linking to a page dip inside another site by formatting a query sting. Like this
<a href=https://www.sitename.com/viewtopic.php?id=5248>Linking to a topic</a>

Passing variables through query string

In many applications we need to pass variables through query string. For example we want to display the product details where product ID is to be passed in query string through a variable. The product ID can be collected from a table so we don't know what is the value but we can use the variable which stores the product ID.

For example let us say we have collected product id from the product table. Read the tutorial on how to collect data from table. Our link with query string will have something like this.

$pid=$nt[product_id];
echo "<a href=product-detail.php?product_id=$pid>Product Details</a>";
You can directly display like this also.
echo "<a href='product-detail.php?product_id=$nt[product_id]'>Product Details</a>";

Chang of data while passing through URL

There is a problem in sending data other than plain text through browser. Empty space and some characters like & if present in the data , will create problem. To maintain the data integrity we have to encode the data before sending them though URL and then decode them again to get back the original data. In PHP encode command is used and in ASP VBScript the command is Server.URLEncode(string)

Security issues while posting data through URL

The most common type of security problem in using data from URL is injection attack. We must sanitize the date before using inside our script or generating any query to manage database.
Declaring variables Cookies to store Information
How can i get data from another website in php?

How can I transfer data from one website to another in PHP?

Look into PHP's curl extension. Alternatively, make your life easier by using a library like Requests for PHP. – Ayush. Oct 24, 2013 at 17:13..
Yes you can use CURL to simulate any HTTP request and it will also track cookies for you. The CURL PHP library is just a wrapper over curl.haxx.se. – Sergiu Paraschiv..

How can I get data from another website?

How do we do web scraping?.
Inspect the website HTML that you want to crawl..
Access URL of the website using code and download all the HTML contents on the page..
Format the downloaded content into a readable format..
Extract out useful information and save it into a structured format..

How extract all URL from website in PHP?

PHP Script to Extract URLs from Webpage.
Step 1: Create a variable to store the source URL. ... .
Step 2: Read source using file_get_contents() function. ... .
Step 3: Strip all tags except <a> ... .
Step 4: Use preg_split() to split a string into substrings. ... .
Step 5: Loop through associative array and print links..

What is get data in PHP?

PHP $_GET. 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.