Use https://www.php.net/manual/en/function.file-get-contents.php
See first example
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to load HTML code of https://www.example.com/ and get the content of the [div class="img-wrapper"]. I want raw data => I want all the HTML tags and texts inside as is in the code.
I've tried DOMXPath, DOMDocument etc. etc. It's either too stupid and can't handle HTML5 or too clever and is stripping all HTML tags inside that DIV.
I have downloaded this file (a single file simple_html_dom.php is enough to make this work):
https://sourceforge.net/projects/simplehtmldom/files/
Simple example is here:
And this code will get all DIVs with class "wrap", and then you can for example loop them and add into a variable:
require('public/simple_html_dom.php');
$html = new \simple_html_dom();
$html->load_file('https://www.example.com/');
$items = $html->find('div[class=wrap]');
$result = '';
$i = 0;
foreach ($items as $item) {
if ($i == 3) {
break;
} else {
$i++;
$result .= $item->innertext;
}
}
return $result;
Please or to participate in this conversation.