1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
function parse_to_html($message)
{
$pattern = array (1 => '#\[b\](.*)\[/b\]#Usi',
2 => '#\[i\](.*)\[/i\]#Usi',
3 => '#\[u\](.*)\[/u\]#Usi',
4 => '#\[color=([^\]]*)\](.*)\[/color\]#Usi',
5 => '#\[size=([\-\+]?\d+)\](.*?)\[/size\]#ise',
6 => '#\[url=([^\]]*)\](.*)\[/url\]#Usi',
7 => '#\[url\](.*)\[/url\]#Usi',
8 => '#\[img\](.*)\[/img\]#Usi',
// 9 => '#\[\*\](.*)\n#iU',
// 9 => '/\[\*\]([^(\[\*\])]*)/i',
// 10 => '#\[list\](.+)\[/list\]#isU',
// 11 => '#\[list=1\](.+)\[/list\]#isU'
9 => "#\[list\](.+)\[/list\]#isU",
10 => '#\[\*\](.+)(?=(</ul>|\[\*\]))#isU',
11 => '#<ul (.+)>(.+)<li>#isU',
12 => '#\[list=1\](.+)\[/list\]#isU');
$replacement = array (1 => '<span style="font-weight: bold">$1</span>',
2 => '<span style="font-style: italic">$1</span>',
3 => '<span style="text-decoration: underline">$1</span>',
4 => '<span style="color: $1">$2</span>',
5 => '<span style="font-size: $1%; line-height: normal">$2</span>',
6 => '<a href="$1" title="$1">$2</a>',
7 => '<a href="$1" title="$1">$1</a>',
8 => '<img src="$1" />',
// 9 => '<li>$1</li>',
// 10 => '<ul>$1</ul>',
// 11 => '<ol>$1</ol>'
9 => '<ul>$1</ul>',
10 => "<li> $1 </li>",
11 => '<ul $1><li>',
12 => '<ol>$1</ol>');
$text = stripslashes($message);
$text = htmlspecialchars($text);
$text = preg_replace($pattern, $replacement, $text);
$text = nl2br($text);
return $text;
} |
Partager