我正在构建用于合并所有屏幕 css 样式表的自定义库,但我不确定如何screen
仅获取媒体类型的样式表。例如:
<!-- This should be fetched -->
<link href="http://www.domain.com/style.css" rel="stylesheet" type="text/css" />
<!-- This should be fetched -->
<link href="http://www.domain.com/ie.css" rel="stylesheet" type="text/css" />
<style type="text/css" media="all">
<!-- This should be fetched -->
@import url("http://static.php.net/www.php.net/styles/phpnet.css");
</style>
<style type="text/css" media="screen">
<!-- This should be fetched -->
@import url("http://static.php.net/www.php.net/styles/site.css");
</style>
<style type="text/css" media="print">
<!-- This should NOT be fetched since it is media type print -->
@import url("http://static.php.net/www.php.net/styles/print.css");
</style>
给定上面的字符串,我只想提取href
和url
值。我不知道该怎么做。虽然我确实尝试过:
preg_match_all("/(url\([\'\"]?)([^\"\'\)]+)([\"\']?\))/", $html, $matches);
print_r($matches);
但它不返回它。
任何使用 php dom、xpath 或 regex 的解决方案来实现这一点?