-1

I have got working regex

$this->html - HTML data

$cssPattern = '/<link rel="stylesheet".*?href="(.+?)"\\s*?\/?>/si';
preg_match_all("{$cssPattern}", $this->html, $matches);

These regex work if rel="stylesheet" is before href but as I mention there is situations where it is after href and in these situation these regex do not work. Is it possible to make / check if rel="stylesheet" is before href or after href

Viktors
  • 935
  • 3
  • 13
  • 33

1 Answers1

0

This RegEx should give you the url of the stylesheet, could be prettier but regex just isn't good for parsing html...

<link.*(?:rel="stylesheet".*|href="(.*)".*){2}.*\/>
TheGreenkey
  • 143
  • 2
  • 8