问题描述:

I want to get html code from page. Page generated by using method get and file_get_contents() not works.

网友答案:

can you be more specific or post your code?

i tried something like this and it works:

<?php
$html=file_get_contents("http://www.google.com");
echo $html;
?>

to use get method you can add your get params to the url you ar calling like this:

<?php
$html=file_get_contents("http://yoururl.com?param1=value&param2=value");
echo $html;
?>
网友答案:
<!DOCTYPE html>
<html>
<head>
    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
 </head>
<body>
<div id="content"></div>
<script>
    /**
    * Test harness to find out the best method for dynamically loading a
    * html page into your app.
    */
    var test_times  = {};
 // here you can use your page name to load
    var test_page   = 'testpage.htm';
    var content_div = document.getElementById('content');

    // TEST 1 = use jQuery to load in testpage.htm and time it.
    /*
    function test_()
    {
        var start = new Date().getTime();
        $(content_div).load(test_page, function() {
            alert(new Date().getTime() - start);
        });
    }

    // 1044
    */

    // TEST 2 = use <object> to load in testpage.htm and time it.
    /*
    function test_()
    {
        start = new Date().getTime();
        content_div.innerHTML = '<object type="text/html" data="' + test_page +
        '" onload="alert(new Date().getTime() - start)"></object>'
    }

    //1579
    */

    // TEST 3 = use httpObject to load in testpage.htm and time it.
    function test_()
    {
       var xmlHttp = new XMLHttpRequest();

       xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
            {
               content_div.innerHTML = xmlHttp.responseText;
               alert(new Date().getTime() - start);
            }
        };

        start = new Date().getTime();

        xmlHttp.open("GET", test_page, true); // true for asynchronous
        xmlHttp.send(null);

        // 1039
      }

      // Main - run tests
       test_();
    </script>
 </body>
</html>
相关阅读:
Top