<?php $text = '<script>alert()</script>'; $text = preg_replace('~\[img\](http(s)?://[^\x27\x22\x3E\x3C]+)\[/img\]~isU', '<img src="\\1" />', $text); echo $text; ?>