I've a string like this:
$url = '<p>IMAGE 1:</p><img src="http://example.com/image1.jpg"><br><p>IMAGE 2:</p><img src="http://www.example.com/image2.jpg"><br><p>IMAGE 3:</p><img src="http://externalsite.com/image3.jpg"><br><p>IMAGE 4:</p><img src="http://www.externalsite.com/image4.jpg">'
example.com is the domain where my webapp is located.
I need:
- check if example.com is http or https
- if https, replace all http://example.com and http://www.example.com in my string to: https://www.example.com (so not include other domains like externalsite.com)
For first point I can use: $isHttps = !empty($_SERVER['HTTPS']) ? true : false;
For second point i'm not sure how create a preg_replace correctly