- preg_replace_callback: documentation ( source)
<?php
$Rtm = '@[ Test Career 12](career:235)@[ Testing11](business:2)@[ Username](user:1)some text';
$Rtm = preg_replace_callback('/@\[([^]]*)\]\(([a-z]+):([^)]*)\)/', function ($match) {
switch($match[2]) {
case 'user':
return "<a href=\"/en/main/profile_page_link/$match[3]\">$match[1]</a>";
break;
case 'business':
return "<a href=\"/en/business/1/about\">$match[1]</a>";
break;
case 'career':
return "<a href=\"/en/main/2/about\">$match[1]</a>";
break;
default:
return "";
break;
}
}, $Rtm);
echo $Rtm;