$text = 'This is a long text containing different image paths like <img src="/site/assets/files/5136/image1.jpg" width="750" />. The text may contain more than one image, here's another one: <img src="/site/assets/files/5136/image1.1.jpg" width="750" />';
Please consider the example text above. I'm looking for a good way to replace period characters in filenames inside a string, that may contain multiple filenames. 'image1.1.jpg' should become 'image1_1.jpg', so the period should be replaced by an underscore. Only period characters that belong to a filename should be replaced. The filename always looks like this:
/site/assets/files/5136/image1.1.jpg
/site/assets/files/425/image1.jpg
/site/assets/files/6524/image2.x.png
The bold parts are variable, the rest of the path is always the same. A filename may or may not contain a period. The extension is .jpg or .png and I only want to target images.
I would like to use PHP to do this.