- preg_match: documentation ( source)
- str_replace: documentation ( source)
<?php
$string = 'ê[B]éîøoo[/B]åaí';
$isMatch = preg_match(
'/\[(\w++)([=]?)([^\]]*?)\]([^\[]*?)\[\/\1\]|\[(HR|\*)\]/',
$string,
$matches
);
if($isMatch) {
echo str_replace(
"[{$matches[1]}]{$matches[4]}[/{$matches[1]}]",
"<b>{$matches[4]}</b>",
$string
);
}