Camen Design Forum

How to save div contetn to text file

append delete Kalimaseven

Whats the php code to automatically save specifig div or ul raw content from live site to text file?.

Reply RSS


append delete #1. Martijn

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!)

There is no need to “register”, just enter the same name + password of your choice every time.

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

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn