As the title suggest i am trying to find all CSS files on a website (for later use i will find all image urls in each of the CSS files on the server).
Now ive tried the following:
$url_to_test = $_GET['url'];
$file = file_get_contents($url_to_test);
$doc = new DOMDocument();
$doc->loadHTML($file);
$domcss = $doc->getElementsByTagName('css');
However the array domcss turned out empty (for a site i know has alot of css files).
So my question is how do i find all css files loaded on a given page?
you should check for link
not css
, change:
$domcss = $doc->getElementsByTagName('css');
to
$domcss = $doc->getElementsByTagName('link');
foreach($domcss as $links) {
if( strtolower($links->getAttribute('rel')) == "stylesheet" ) {
echo "This is:". $links->getAttribute('href') ."<br />";
}
}
Try this:
preg_match('/<link rel="stylesheet" href="(.*?)" type="text\/css">/',$data,$output_array);