Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 907861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:37:16+00:00 2026-05-15T16:37:16+00:00

How can I load the content of a web page into a variable? I

  • 0

How can I load the content of a web page into a variable?

I need to store the HTML in a string.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:37:17+00:00Added an answer on May 15, 2026 at 4:37 pm

    Provided allow_url_fopen is enabled, you can just use file_get_contents :

    $my_var = file_get_contents('http://yoursite.com/your-page.html');
    

    And, if you need more options, take a look at Stream Functions — there is an example on the stream_context_create manual page where a couple of HTTP-headers are set.

    If `allow_url_fopen` is disabled, another solution is to work with [**curl**][5] — means a couple more lines of code, though.

    Something as basic as this should work in the simplest situations :

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://stackoverflow.com/");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $my_var = curl_exec($ch);
    curl_close($ch);
    

    But note that you might need some additional options — see the manual page of curl_setopt for a complete list.

    For instance :

    • I often set CURLOPT_FOLLOWLOCATION, so redirects are followed.
    • The tiemout-related options are quite often useful too.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I achieve this? I am trying to load content from the database
Can I load an stand alone aspx page in another stand alone aspx page
When using PyWin I can easily load a python file into a fresh interactive
I have a CSV of file of data that I can load in R
I have a little problem with a Listview. I can load it with listview
I am trying to dynamicaly compile code using CodeDom. I can load other assemblies,
How can I load an external JavaScript file using a bookmarklet? This would overcome
How can one load custom (not an image, nor a sound file) resource file
If I'm running a signed Java applet. Can I load additional classes from remote
How can I dynamically load a usercontrol in ASP.NET if I dont have access

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.