Camen Design Forum

How to save div contetn to text file


What exactly do you want to save? You can use `file_put_contents` [1] to store the contents of a variable in a file.

If you need to extract HTML from a live external website, you can use DOMDocument to read the HTML [2]:

$dom = new DOMDocument();

Then use XPath [3] to get whatever element you want:

$xpath = new DOMXPath($dom);
$element = $xpath->query('//div[@id="example"]')->item(0);

Now you can get the HTML of just that element into a variable [4] and save it to a file:

$html = $dom->saveHTML($element);
file_put_contents('myfile.html', $html);

Hope that gives you an idea of how things work!



(Leave this as-is, it’s a trap!)

Only the original author or a moderator can append to this post.

Pro tip: Use markup to add links, quotes and more.

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn