$mes=preg_replace('#\[img\](http|https)://(.*).(gif|png|jpg|jpeg)\[/img]#sU','<img src="/img-src.php?img=\1://\2.\3" alt="Изображение" style="max-width:100%;">',$mes);