0

I've got this code:

$path = $site."/".$stylesheets[0] ("http://example.com/thecssfile.css")
$css = file($path);

But now, there is the sourcecode of http://example.com in the $css variable. How can I get the code of http://example.com/thecssfile.css. If I set the $path variable directly to "http://example.com/thecssfile.css" it works but I want it dynamic.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Tom291
  • 509
  • 1
  • 4
  • 14
  • There are plenty questions about parsing HTML in any language - makes sure to search to demonstrate that you've tried to find solution already (you may even find answer to your question like http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – Alexei Levenkov Mar 06 '16 at 21:57
  • Yes, I tried this allready. My way works but not dynamic – Tom291 Mar 06 '16 at 21:58
  • If you've already tried to parse HTML and get links (and that did not work for your case) you need to clarify what "dynamic" means for you. – Alexei Levenkov Mar 06 '16 at 21:59
  • I try to get the code of all css files on a website, which was choosen by the user. The stylesheet names are different. So the path must be different for all sites (dynamic) – Tom291 Mar 06 '16 at 22:01
  • @Tom291: You need to parse the HTML and find the `` tags. – SLaks Mar 07 '16 at 01:37

1 Answers1

1

You assume, that $stylesheets[0] is thecssfile.css, but it is not. You can see this by var_dump($stylesheets[0])

You need to make sure, it has the value you want. In your case:

$stylesheets = [0 => 'thecssfile.css']
Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111