I have a very complex string and i want to find and replace all urls that end with .jpg, .png, or .gif with a static url. For example;
$string = "Lorem ipsum dolor sit amet, http://www.website.com/images/some.jpg; consul delicata comprehensam eos at. Mea rebum laudem deterruisset et, ex epicuri constituto his. Sea ad appareat democritum. http://www.anotherwebsite.com/images/some.png Omnis vituperata dissentiunt an duo. Sumo diceret lobortis at sed, singulis aliquando prodesset ex sit.";
$regex = ?;
$static_image_url= "http://new_image_url";
return preg_replace($regex, $static_image_url, $string);
Please note this string may be more complex than this, urls are dynamic and this is NOT HTML.
Thank you very much in advance.
Best Regards,
EDIT:
This one worked for this case;
return preg_replace('/https?:\/\/[^ ]+?(?:\.jpg|\.png|\.gif)/', $static_image_url, $string);