How Do I Read the Contents of a Remote Web Page Using PHP?

104 9
    • 1). Open the URL and assign the contents to a variable. This command simply opens the URL with no options. To open a URL, use the following code:
      $contents = file_get_contents('http://my_domain.com/somePage.php');

    • 2). Assign some optional parameters. An options array is created to tell the application how to open the URL. For instance, in this example, an array is set up to post information to an external web page form and return the results. The following code builds the array:
      $options = array( 'return_info' => true, 'method' => 'post')
      In this example, the "return_info" parameter tells PHP to return the information in the website form. The "method" parameter is the typical "post" value used for website forms.

    • 3). Load the optional parameters along with the content URL set up in step 1. The following code illustrates how to return form information:
      $result = load($content',$options);

    • 4). Print the results for the user. The following code prints the results to the user's screen:
      print_r($result);

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.