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;
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
[img:123]http://www.test.com/%20%20abc.jpg[/img:123]

preferences:
58.14 ms | 406 KiB | 5 Q