Camen Design Forum


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

To delete this post you must be either the original author or a designated moderator.
The content of the post will be removed but the name and date will remain.

  • The post will be removed completely from the thread, rather than blanked
  • Only posts on the last page of the thread can be removed completely (so as to not break permalinks)

RE[1]: 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!


Your friendly neighbourhood moderators: Kroc, Impressed, Martijn