3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string= '[mycode="gallery" type="single" id="1" data="only"]'; echo preg_replace_callback('/\[([^\]]+)\]/', function($match) { $string = preg_replace('/\h*mycode="([^"]+)"\h*/', '$1/mycode', $match[1]); $string = preg_replace('/\h*type="([^"]+)"\h*/', 'mycode_$1.php', $string); $string = preg_replace('/\h*id="([^"]+)"\h*/', '?id=$1', $string); $string = preg_replace('/\h*data="([^"]+)"\h*/', '&data=$1', $string); return $string; }, $string);

preferences:
22.27 ms | 405 KiB | 5 Q