PHP GET HTML source code WebPages using DOM Parser

PHP GET HTML source code WebPages using DOM Parser

In this Post We Will Explain About is PHP GET HTML source code WebPages using DOM Parser With Example and Demo.Welcome on – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to how to get html source code of a website using phpExample

In this post we will show you Best way to implement Parse Web Pages with PHP Simple HTML DOM Parser, hear for PHP to get html source, then parse values within certain DIV tagswith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

PHP: How to get (view) html source code of a website

$your_domain = '';
$file_handel = fopen($your_domain, 'r');
$data_content = stream_get_contents($file_handel);

echo "<textarea rows='20' cols='80'>$data_content</textarea>";

Read source code with PHP

$ch = curl_init('');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data_content = curl_exec($ch);
echo $data_content;

Using PHP to parse html tables and extract values

$data_content = '<ul>
 <li>item 1</li>
 <li>item 2</li>
 <li>item 3</li>
 <li>pakainfo 1 2 3..</li>
 <li>pakainfo 1 2 3..</li>

$dom = new DOMDocument();
$userdataList = $dom->getElementsByTagName('ul');
foreach ($userdataList->item(0)->getElementsByTagName('li') as $userdataList) {
    echo $userdataList->nodeValue.'<br />';                    

Step 1 : curl using PHP to parse with PHP file data Get


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//all result
$result = curl_exec($ch);
//data json format
$obj = json_decode($result, TRUE);
//count total records
$total_load_record = count($obj['items']);

Step 2 : curl using PHP parse to HTML get source code

$string_data = str_replace("(titaldata)","",$obj['items'][6]['title']);
	$u_id = $obj['items'][$i]['id'];
	$string = str_replace(' ', '_', $string_data);
	$url = "".$string;
	$ch = curl_init();

	// Tell simple curl what URL we want.
	curl_setopt($ch, CURLOPT_URL, $url);

	// Set simple this if you ant don't want the content simple header.
	curl_setopt($ch, CURLOPT_HEADER, 0);

	// your Download the HTML part from the URL.
	$data_content = curl_exec($ch);

	/* Insert Records*/
	$dom = new DOMDocument();
	$dom->validateOnParse = true; 
	$dom->preserveWhiteSpace = false;
	$xpath = new \DOMXpath($dom);
	$rows  = $xpath->query('//tr[@class="cardtablerow"]');
	$value = "";
	$total_row = $rows->length;


Also Read This ๐Ÿ‘‰   Laravel 6 change date format example Tutorial

I hope you have Got What is PHP HTML source code DOM Parser And how it works.I would Like to have FeadBack From My Blog( readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article( Are Most Always Welcome.