Ver original$texto = 'a [x foo="bar"]b[/x] c';$texto = preg_replace_callback('/\[(\w+)([^[\]]*)\](.+?)\[\/\1\]/', function($matches) { var_dump($matches);}, $texto);