3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = "[img]http://www.test.com/ abc.jpg[/img]"; $uid = 123; $text = preg_replace_callback( "#\[img]((?:https?|ftps?)://[^?&=\#\"<]*?\.(?:jpe?g|gif|png))\[/img]#i", function ($m) use ($uid) { return "[img:$uid]" . str_replace(' ', '%20', $m[1]) . "[/img:$uid]"; }, $text ); echo $text;

preferences:
31.69 ms | 405 KiB | 5 Q