I thought this was an easy task, but apparently not.
$dom = new DOMDocument();
$dom->loadHTMLFile("myhtml.html");
$timestamp = $dom->getElementById('timestamp');
$timestamp = $dom->saveHTML($timestamp);
$matches_out = array();
if (preg_match_all('/<div id="timestamp">(.*)<\/div>/', $timestamp, $matches_out)) {
$timestamp = $matches_out[0];
}
echo $timestamp;
I need to get the value out of the array and store it in the $timestamp variable. When I use print_r() I get Array ( [0] =>1422936994). I thought that mean to get my timestamp I just do $matches_out[0] because I can see it right there on the zero index, or am I missing something.
Trying to echo it out gets me this: Notice: Array to string conversion in C:\xampp\htdocs\myscript.php on line 10
preg_match_all. Why not use the DOMDocument object methods? For example the getElementsByTagName method.