function generate_movies_tags($html_content, $document) { $moviematchestag = $document->CreateElement('moviematches'); $matches = array(); preg_match_all("#<a href='/film/fichefilm_gen_cfilm=(\\d+).html'><img.+src='.+'.+alt='.+' />#SUmis", $html_content, $matches); foreach ($matches[1] as $resultat) { if (file_exists("/tmp/allocine_api/" . $resultat . ".xml")) { $doc = createDocument(); $doc->load("/tmp/allocine_api/" . $resultat . ".xml"); $nodeList = $doc->getElementsByTagName('movie')->item(0)->childNodes; $movietag = $document->CreateElement('movie'); if ($nodeList) { foreach ($nodeList as $node) { $tmp = $document->importNode($node, true); $movietag->appendChild($tmp); } } } else { $movietag = generate_movietag($resultat, $document); } $moviematchestag->appendChild($movietag); } return $moviematchestag; }
function generate_movies_tags($results, $document, $limit = 0) { $moviematchestag = $document->CreateElement('moviematches'); $i = 1; foreach ($results as $res) { $movietag = generate_movietag($res, $document); $moviematchestag->appendChild($movietag); if ($limit > 0) { if (++$i > $limit) { break; } } } return $moviematchestag; }