hi

How can i get the html of a given web page?..
I have the url of the web page...please help me ....very urgent...Thank you

Ditty

Dani AI

Generated

Quick practical summary for : the simplest manual route is the browser "Save Page As" that mentioned, and correctly pointed out file_get_contents() for quick GETs. For anything that must run reliably on a server (timeouts, redirects, headers, cookies, SSL) prefer the cURL extension or an HTTP client library. file_get_contents() works for trivial cases but can be disabled by allow_url_fopen and gives little control or error reporting.

A robust minimal cURL pattern (GET, follow redirects, timeout, gzip support, basic error check):

<?php
$url = 'https://example.com/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; PHP script)');
curl_setopt($ch, CURLOPT_ENCODING, ''); // accept gzip/deflate
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$html = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($html === false) {
    $err = curl_error($ch);
    // handle/report error
}
curl_close($ch);

For extracting data from the returned HTML, use DOM parsing (DOMDocument + DOMXPath) rather than regex. Example pattern:

<?php
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$title = trim($xpath->evaluate('string(//title)'));

Troubleshooting and practical notes: check that the PHP cURL extension is installed and that allow_url_fopen/open_basedir settings are not blocking access. Server-side fetches do not run JavaScript—sites that require rendering need a headless browser (Puppeteer/Playwright) or a rendering service. Always handle HTTP status codes, follow robots.txt and site terms, throttle requests and cache responses to avoid bans. For larger projects, consider a higher-level client such as Guzzle for retries, middleware, and cleaner code.

Recommended Answers

All 3 Replies

which web page u r asking for ?

however, if u r having url, just open that site and u can get its html by going to file option and then click "SAVE PAGE AS" option in "FILE" menu and save it as "WEB PAGE, COMPLETE".

This will create a folder with the complete css and images and a html file

I want the php code to get the html of the web page corresponding to that particular url...Actually i want to fetch something from other sites

Just use the file_get_contents() function. Very simple but make sure you place the http:// or https:// before the domain. Below is an example:

<?
$webpage_data=file_get_contents("http://www.google.com/");
echo $webpage_data;
?>
commented: smart +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.