In short, I'm utilizing pre_replace to find style sheets and essentially proxy this experience for viewers on my website, I use the external domain and prepend it to the current href. The style sheet starts like so.
<link rel="stylesheet" type="text/css" href="/assets/css/base.css">
I will take the href and prepend the domain to be
<link rel="stylesheet" type="text/css" href="http://www.website.com/assets/css/base.css">
My issue is, when I encounter a site that does not include HTTP/HTTPS
<link rel="stylesheet" type="text/css" href="//cdn.website.com/assets/css/base.css">
Then my current preg replace would not function and return the stylesheet to the following
<link rel="stylesheet" type="text/css" href="http://www.website.com//cdn.website.com/assets/css/base.css">
Is it possible to create some sort of If then with preg_replace to not manipulate the "//" hrefs and only replace the ones with no absolute base domain?
Current preg_replace being used:
$html = file_get_contents($website_url);
$domain = 'website.com';
$html = preg_replace("/(href|src)\=\"([^(http)])(\/)?/", "$1=\"$domain$2", $html);
echo $html;
hrefattribute's contents.