- preg_replace_callback: documentation ( source)
- str_replace: documentation ( source)
<?php
$text = "[[Some text]] and [[one more here]]";
echo preg_replace_callback("/\[\[(.+?)]]/", function($m) {
return '<a href="/XLab/?document=' . str_replace(' ', '_', $m[1]) . '">' . $m[1] . '</a>';
}, $text);