Nieuw lid |
|
Ik heb een probleem met het parsen van de [list] tag. Hier achter zet mijn parser steeds een <br />.
nl2br(); zet de <br /> maar als ik die zou weglaten zet hij nergens nog een <br /> tag?
Hoe kan ik dit nu oplossen?
Hier is het probleem te zien: http://skelton.....php?tid=2
Dit is mijn ubb parser:
<?
class ubb {
function parsen($text) {
$text = nl2br(htmlspecialchars($text));
$ubb = array("email1" => "/\[email\](.*?)\[\/email\]/si",
"email2" => "/\[email=(.*?)\](.*?)\[\/email\]/si",
"email3" => "#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i",
"url1" => "#\[url\](\S+?)\[/url\]#si",
"url2" => "#\[url=(\S+?)\](.*?)\[/url\]#si",
"url3" => "#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)?)#i",
"url4" => "#([\n ])http://www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)?)#i",
"url5" => "#([\n ])http://([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)?)#i",
"b" => "/\[b\](.*?)\[\/b\]/Ssi",
"u" => "/\[u\](.*?)\[\/u\]/Ssi",
"i" => "/\[i\](.*?)\[\/i\]/Ssi",
"code" => "#\[code\](.*?)\[/code\]#si",
"quote" => "#\[quote=(.*?)\](.*?)\[/quote\]#si",
"quote2" => "#\[quote](.*?)\[/quote\]#si",
"lijst1" => "#\[list](.*?)\[/list]#si",
"lijst2" => "#\[list=1\](.*?)\[/list]#si",
"lijst3" => "#\[li\](.*?)\[/li\]#si"
);
$html = array("email1" => '<a href="mailto:\\1">\\1</a>',
"email2" => '<a href="mailto:\\1">\\2</a>',
"email3" => '<a href="mailto:\\2@\\3">\\2@\\3</a>',
"url1" => '<a href="\\1" target="_blank">\\1</a>',
"url2" => '<a href="\\1" target="_blank">\\2</a>',
"url3" => '<a href="http://www.\\2.\\3\\4" target="_blank">www.\\2.\\3\\4</a>',
"url4" => '<a href="http://www.\\2.\\3\\4" target="_blank">www.\\2.\\3\\4</a>',
"url5" => '<a href="http://\\2.\\3\\4" target="_blank">http://\\2.\\3\\4</a>',
"b" => '<strong>\\1</strong>',
"u" => '<u>\\1</u>',
"i" => '<em>\\1</em>',
"code" => '<strong>Code:</strong><div class="code">\\1</div>',
"quote" => '<strong>Quote:</strong><div class="quote"><em><strong>\\1</strong> schreef:</em><br />\\2</div>',
"quote2" => '<strong>Quote:</strong><div class="quote">\\1</div>',
"lijst1" => '<ul>\\1</ul>',
"lijst2" => '<ol type="1">\\1</ol>',
"lijst3" => '<li>\\1</li>'
);
$txt = preg_replace($ubb, $html, $text);
return stripslashes($txt);
}
}
$ubb = new ubb;
?>
<? class ubb { function parsen($text) { $ubb = array("email1" => "/\[email\](.*?)\[\/email\]/si", "email2" => "/\[email=(.*?)\](.*?)\[\/email\]/si", "email3" => "#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", "url1" => "#\[url\](\S+?)\[/url\]#si", "url2" => "#\[url=(\S+?)\](.*?)\[/url\]#si", "url3" => "#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)?)#i", "url4" => "#([\n ])http://www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)?)#i", "url5" => "#([\n ])http://([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)?)#i", "b" => "/\[b\](.*?)\[\/b\]/Ssi", "u" => "/\[u\](.*?)\[\/u\]/Ssi", "i" => "/\[i\](.*?)\[\/i\]/Ssi", "code" => "#\[code\](.*?)\[/code\]#si", "quote" => "#\[quote=(.*?)\](.*?)\[/quote\]#si", "quote2" => "#\[quote](.*?)\[/quote\]#si", "lijst1" => "#\[list](.*?)\[/list]#si", "lijst2" => "#\[list=1\](.*?)\[/list]#si", "lijst3" => "#\[li\](.*?)\[/li\]#si" ); $html = array("email1" => '<a href="mailto:\\1">\\1</a>', "email2" => '<a href="mailto:\\1">\\2</a>', "email3" => '<a href="mailto:\\2@\\3">\\2@\\3</a>', "url1" => '<a href="\\1" target="_blank">\\1</a>', "url2" => '<a href="\\1" target="_blank">\\2</a>', "url3" => '<a href="http://www.\\2.\\3\\4" target="_blank">www.\\2.\\3\\4</a>', "url4" => '<a href="http://www.\\2.\\3\\4" target="_blank">www.\\2.\\3\\4</a>', "url5" => '<a href="http://\\2.\\3\\4" target="_blank">http://\\2.\\3\\4</a>', "b" => '<strong>\\1</strong>', "u" => '<u>\\1</u>', "i" => '<em>\\1</em>', "code" => '<strong>Code:</strong><div class="code">\\1</div>', "quote" => '<strong>Quote:</strong><div class="quote"><em><strong>\\1</strong> schreef:</em><br />\\2</div>', "quote2" => '<strong>Quote:</strong><div class="quote">\\1</div>', "lijst1" => '<ul>\\1</ul>', "lijst2" => '<ol type="1">\\1</ol>', "lijst3" => '<li>\\1</li>' ); } } $ubb = new ubb; ?>
Alvast bedankt.
|