Finally I last got a solution (i think) to my problem. Here is how I solved it;
//The string to be parsed
$str='[ bold ]blaom[/bold][ link =http://www.aftonbladet.se ]ab aaaa[ italic ] a[/link] g//g/[/italic]hf g[underrubrik]ab </html>ag aa[/underrubrik] sd fh dsf[/link] sdfj dsfjh jh dsfj hdfs';
$search_pattern=array(
'#\[\s*(bold)\s*\](.*?)\[/\s*\1\s*\]#',
'#\[\s*(italic)\s*\](.*?)\[/\s*\1\s*\]#',
'#\[\s*(underrubrik)\s*\](.*?)\[/\s*\1\s*\]#',
'#\[\s*(link)\s*=(.+?)\s*\](.*?)\[/\s*\1\s*\]#'
);
$replace_pattern=array(
'<B>$2</B>',
'<I>$2</I>',
'<H2>$2</H2>',
'<A HREF="$2">$3</A>'
);
$str=htmlentities($str);
$hits=preg_replace($search_pattern, $replace_pattern,$str);
echo"<h1>String</h1>";
echo $str;
echo"<h1>Parsing</h1>";
echo $hits;
echo"<br>";
If you need some more own tags simply add a regexp in the search array and a replacement exp in the replace array.
Anyhow Mordecai posted a tip to use str_replace instead. Does this win much in speed in executing the script or is my script fast enough? Any opinions here appreciated.
Thanks in advance.