SnakeV
10-23-2015, 08:43 PM
I'm trying to include a CDN in all images embeded in posts.
For this purpose i have created a plugin with a simple preg_replace:
preg_replace("/<img .*?(?=src=\"http:\/\/)src=\"http:\/\/([^\"]+)\"/si", "<img src=\"http://i1.wp.com/$1\"", $this->post['message']);
My problem is that it replaces in some posts more than it should:
For example with this it replaces everything instead of just the img src.
<img src="http://www.vbulletin.com/images/smilies/spinny.gif" border="0" alt="" title="Spinny" class="inlineimg" />) <br /> <br /> example text text text
Any clearer way to do the preg_replace?
I just need to append http://i1.wp.com/ in the img src (and remove the http://) to get an URL like this:
http://i1.wp.com/www.vbulletin.com/images/smilies/spinny.gif
Thanks!
For this purpose i have created a plugin with a simple preg_replace:
preg_replace("/<img .*?(?=src=\"http:\/\/)src=\"http:\/\/([^\"]+)\"/si", "<img src=\"http://i1.wp.com/$1\"", $this->post['message']);
My problem is that it replaces in some posts more than it should:
For example with this it replaces everything instead of just the img src.
<img src="http://www.vbulletin.com/images/smilies/spinny.gif" border="0" alt="" title="Spinny" class="inlineimg" />) <br /> <br /> example text text text
Any clearer way to do the preg_replace?
I just need to append http://i1.wp.com/ in the img src (and remove the http://) to get an URL like this:
http://i1.wp.com/www.vbulletin.com/images/smilies/spinny.gif
Thanks!