<?php
$contents = file_get_contents('http://localhost:8000/index.html');
$contents = preg_replace('/<!--.*-->/', '', $contents);
{
preg_match_all('/<link rel="stylesheet" href="(.*\.css).*/', $contents, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$inner = file_get_contents('./static/'.$match[1]);
$inner = preg_replace('#/\*([^*]|\*[^/])*\*/#s', '', $inner);
$inner = trim($inner)."\n";
$contents = str_replace($match[0], "<style>\n".$inner."\t\t</style>", $contents);
}
}
{
preg_match_all('/<script src="(.*\.js).*/', $contents, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$inner = file_get_contents('./'.$match[1]);
$inner = preg_replace('#/\*([^*]|\*[^/])*\*/#s', '', $inner);
$inner = preg_replace('#^\s*//.*#m', '', $inner);
// $inner = preg_replace('#^\s*console\..*#m', '', $inner);
$inner = trim($inner)."\n";
$contents = str_replace($match[0], "<script>\n".$inner."\t\t</script>", $contents);
}
}
$contents = preg_replace('/\s*\n\s*/', '', $contents);
echo $contents;
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme