Untitled
By: a guest | Sep 13th, 2008 | Syntax:
PHP | Size: 0.60 KB | Hits: 260 | Expires: Never
<?php
$text = '1] Good: [b]Bold[/b][i]Italic[/i]
2] Good: [b][i]Both[/i][/b]
3] Bad: [b][i]Alternating tags[/b][/i]
4] Bad: [b][i]Misplaced tag[/b]
5] Good: [b][i][u][s]All tags[/s][/u][/i][/b]
6] Bad: [b][i][u][s]Swapped end tags[/s][/i][/u][/b]';
echo "<pre>$text<hr>";
// replace good tag pairs
while(preg_match('#\[([bisu])\]((?:(?!\[/?[bisu]\]).)*)\[/\1\]#is',$text)){
$text=preg_replace('#\[([bisu])\]((?:(?!\[/?[bisu]\]).)*)\[/\1\]#is','<\1>\2</\1>',$text);
}
// replace bad tags
// htmlencode to display example
?>