Last active
May 23, 2020 23:14
-
-
Save conkonig/60e943173b94ffd1df4fe76881d7ece1 to your computer and use it in GitHub Desktop.
PHP get latest html template in a directory - (bug: didnt work past num 9 for some reason)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// example 1 | |
$episodes = preg_grep('~^good-.*\.html$~', scandir(__DIR__)); | |
$d = new DOMDocument; | |
$mock = new DOMDocument; | |
$d->loadHTML(file_get_contents(__DIR__ . '/' . end($episodes))); | |
$body = $d->getElementsByTagName('body')->item(0); | |
foreach ($body->childNodes as $child) { | |
$mock->appendChild($mock->importNode($child, true)); | |
} | |
echo $mock->saveHTML(); | |
// example 2 | |
function getHTMLFromFileForEmail() | |
{ | |
ob_start(); | |
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="center">'; | |
$html_files = preg_grep('~^index.*\.html$~', scandir(__DIR__)); | |
$d = new DOMDocument; | |
$mock = new DOMDocument; | |
$d->loadHTML(file_get_contents(__DIR__ . '/' . end($html_files))); | |
$body = $d->getElementsByTagName('html')->item(0); | |
foreach ($body->childNodes as $child) { | |
$mock->appendChild($mock->importNode($child, true)); | |
} | |
echo $mock->saveHTML(); | |
echo "</td></tr></table>"; | |
$html = ob_get_contents(); | |
ob_end_clean(); | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment