- var_dump: documentation ( source)
- urlencode: documentation ( source)
- str_replace: documentation ( source)
- preg_replace: documentation ( source)
<?php
$text = 'qwe <img src="http://img7.arrivo.ru/inlabu/47/0/sfsjho.jpg" /> sdfj <img src="http://img7.arrivo.ru/inlabu/47/0/sfsjho.jpg" style="width: 200px;" /> gbfkljho <img src=\'http://img7.arrivo.ru/inlabu/47/0/sfsjho.jpg\' /> sdfj <img src=\'http://img7.arrivo.ru/inlabu/47/0/sfsjho.jpg\' style=\'width: 200px;\' /> gbfkljho <img src=http://img7.arrivo.ru/inlabu/47/0/sfsjho.jpg /> sdfj <img style="width: 200px;" src=http://img7.arrivo.ru/inlabu/47/0/sfsjho.jpg /> gbfkljho';
$oldImage = [
'path' => 'inlabu',
'id' => 47,
'url' => 'sfsjho.jpg',
];
$text = preg_replace('|<img(.*)(?!.*width)(.*)http://img7\.arrivo\.ru/'.$oldImage['path'].'/'.$oldImage['id'].'/\d/'.str_replace('.', '\.', urlencode($oldImage['url'])).'(.*)(?!.*width)(.*)>|U', '<img\\1\\2http://google.com\\3\\4>', $text);
var_dump($text);