要提取CSS并生成单独的文件,可以使用PHP中的以下方法:
$html = file_get_contents('example.html'); preg_match_all('/<style[^>]*>(.*?)<\/style>/is', $html, $matches); $css = implode("\n", $matches[1]); // 保存提取出的CSS内容到一个单独的CSS文件中 file_put_contents('styles.css', $css); include('simple_html_dom.php'); $html = file_get_html('example.html'); $css = ''; foreach($html->find('style') as $style) { $css .= $style->innertext; } // 保存提取出的CSS内容到一个单独的CSS文件中 file_put_contents('styles.css', $css); 这些方法可以帮助你从HTML文件中提取CSS样式并保存到单独的CSS文件中。