I am building my custom library for merging all screen css stylesheets but I am not sure how to get stylesheets for the media type screen only. For example:
<!-- 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>
Given above string, I just want to extract href and url values. I don't know how to go about with that. Although I did try:
preg_match_all("/(url\([\'\"]?)([^\"\'\)]+)([\"\']?\))/", $html, $matches);
print_r($matches);
But it doesn't return it.
Any solution with php dom, xpath or regex to achieve that ?