I'm using file_get_contents() to get source code of a page but I fail in some websites that uses CSS like this:
background: url("/media/image")
background: url(/media/image)
background: url('/media/image')
// etc...
Now, I want to know how can I edit that CSS and add my website, so it will look like this:
background: url("http: //example.com/media/image")
background: url('http: //example.com/media/image')
background: url(http://example/media/image)
// etc...
. Here is my code:
$regex = "-(src\s*=\s*['\"])(((?!'|\"|http://|https://|//).)*)(['\"])-i";
I'm doing this on the src attribute of an HTML tag. I hope I'm helping
echo preg_replace('~url\(("|\')?/?(.*?)(?:\1)?\)~', 'url($1http://www.example.com/$2$1)', $css) . "\n";, no? Where$cssis one of your three examples.file_get_contents()? To me it pretty much sounds like you're importing someone elses website and replace the stuff you can't import. Something smells a bit to much like phishing here..