开发者

Extracting linked CSS files with PHP

开发者 https://www.devze.com 2023-02-20 03:28 出处:网络
Whats the 开发者_如何学运维best way to parse HTML and extract linked CSS files using PHP?DOMDocument can probably help you out:

Whats the 开发者_如何学运维best way to parse HTML and extract linked CSS files using PHP?


DOMDocument can probably help you out:

$dom = new DOMDocument();
$dom->loadHTMLFile('file.html'); // Can replace with $dom->loadHTML($str);

$link_tags = $dom->getElementsByTagName('link');

foreach($link_tags as $link_tag)
{
   // if $link_tag rel == stylesheet
   //   get href value and load CSS
}


Here is a simple solution using regular expressions.

$content = '...';

$n = preg_match_all('/"([^"]+?\.css)"/', $content, $matches);
if ($n !== FALSE && $n > 0) {
    var_dump($matches[1]);
}


I would use curl class to get the HTML file, then use the DOMDocument class to parse the HTML for CSS links. If you are looking for more, you will have to be more specific.


DOMDocument http://it.php.net/domdocument

check in php documentation

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号