3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

preferences:
54.05 ms | 402 KiB | 5 Q