PHP interesse |
|
Hallo,
Hieronder een gedeelte van m'n UBB systeem:
<?php
function xhtmlcode($str)
{
$font = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $str);
$ret = preg_replace('#color="(.*?)"#', 'style="color: \\1; font-family:Verdana; font-size:11px;"', $font);
return $ret;
}
function ubb($in)
{
$in = stripslashes($in);
$in = htmlspecialchars($in);
$in = nl2br($in);
$in = preg_replace("_\[code\](.*?)\[/code\]_ise", "code('\\1')", $in); //[code ] tag Replaces
/* UBB Replaces */
/*-----------------------------------------------------------------------------------*/
$input = array("#\[(b|strong)\](.*?)\[\/(b|strong)\]#si",
"#\[(i|em)\](.*?)\[\/(i|em)\]#si",
"#\[u\](.*?)\[\/u\]#si",
"#\[(s|strike)\](.*?)\[\/(s|strike)\]#si",
"#\[url\]((http|https|ftp)://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\[/url\]#is", //[url]xx://www.***.nl.nl[/url]
"#\[url\]((www|www1|www2|www3|www4|www5)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\[/url\]#is", //[url]www.***.nl[/url] (zonder xx://)
"#\[url=((http|https|ftp)://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is", //[url=xx://www.***.nl]***.nl[/url]
"#\[url=((www|www1|www2|www3|www4|www5)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is", //[url=www.***.nl]***.nl[/url] (zonder xx://)
"#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si",
"#\[email=([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\](.*?)\[\/email\]#si");
$output = array("<strong>\\2</strong>",
"<em>\\2</em>",
"<u>\\1</u>",
"<strike>\\2</strike>",
"<a href='\\1' target='_blank'>\\1</a> ",
"<a href='http://\\1' target='_blank'>\\1</a>",
"<a href='\\1' target='_blank'>\\3</a>",
"<a href='http://\\1' target='_blank'>\\3</a>",
"<a href='mailto:\\1'>\\1</a>",
"<a href='mailto:\\1'>\\3</a>");
$in = preg_replace($input, $output, $in);
/*-----------------------------------------------------------------------------------*/
/* UBB Replaces */
return $in;
}
function code($code)
{
$code = str_replace("<br />", "", $code); //Om te zorgen voor goede weergave ivm. nl2br bij ubb();
$code = html_entity_decode($code);
$code = trim($code);
$code = @highlight_string($code, true);
$code = xhtmlcode($code); //Om font te veranderen in <span style='.... en lettertype als verdana
$regels = explode("<br />", $code);
$nummers = count($regels);
$blok = "<table bgcolor='#f1f5f6' cellpadding='3' cellspacing='0' style='border:1px solid #3f7082;' width='506'>
<tr>
<td width='100%'><div style='overflow:auto; overflow-x:scroll; width:500px;'>
<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse;' width='100%'>
<tr>
<td width='100%' colspan='2' bgcolor='#deecf1' style='font-family:Verdana; font-size:11px; font-weight:bold; padding:2px;'>C o d e</td>
</tr>
<tr>
<td width='25' nowrap valign='top' bgcolor='#f1f5f6' style='font-family:Verdana; font-size:11px;'>";
for($i=1; $i<=$nummers; $i++)
{
$blok .= $i."<br />\n";
}
$blok .= " </td>
<td width='100%' nowrap valign='top' bgcolor='#f1f5f6' style='font-size:12px;'>".$code."</td>
</tr>
</table>
</div></td>
</tr>
</table>";
return $blok;
}
if(!isset($_POST['submit']))
{
echo "<form method='post'>
<textarea style='width:506px; height:150px;' name='code'></textarea><br />
<input type='submit' name='submit' value='Highlight code!' />
</form>";
} else {
echo "<form method='post'>
<textarea style='width:506px; height:150px;' name='code'>".htmlspecialchars(stripslashes($_POST['code']))."</textarea><br />
<input type='submit' name='submit' value='Highlight code!' />
</form><br />";
echo ubb($_POST['code']);
}
?>
<?php function xhtmlcode($str) { $ret = preg_replace('#color="(.*?)"#', 'style="color: \\1; font-family:Verdana; font-size:11px;"', $font); return $ret; } function ubb($in) { $in = preg_replace("_\[code\](.*?)\[/code\]_ise", "code('\\1')", $in); //[code ] tag Replaces /* UBB Replaces */ /*-----------------------------------------------------------------------------------*/ $input = array("#\[(b|strong)\](.*?)\[\/(b|strong)\]#si", "#\[(i|em)\](.*?)\[\/(i|em)\]#si", "#\[u\](.*?)\[\/u\]#si", "#\[(s|strike)\](.*?)\[\/(s|strike)\]#si", "#\[url\]((http|https|ftp)://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\[/url\]#is", //[url]xx://www.***.nl.nl[/url] "#\[url\]((www|www1|www2|www3|www4|www5)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\[/url\]#is", //[url]www.***.nl[/url] (zonder xx://) "#\[url=((http|https|ftp)://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is", //[url=xx://www.***.nl]***.nl[/url] "#\[url=((www|www1|www2|www3|www4|www5)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is", //[url=www.***.nl]***.nl[/url] (zonder xx://) "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si", "#\[email=([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\](.*?)\[\/email\]#si"); $output = array("<strong>\\2</strong>", "<em>\\2</em>", "<u>\\1</u>", "<strike>\\2</strike>", "<a href='\\1' target='_blank'>\\1</a> ", "<a href='http://\\1' target='_blank'>\\1</a>", "<a href='\\1' target='_blank'>\\3</a>", "<a href='http://\\1' target='_blank'>\\3</a>", "<a href='mailto:\\1'>\\1</a>", "<a href='mailto:\\1'>\\3</a>"); /*-----------------------------------------------------------------------------------*/ /* UBB Replaces */ return $in; } function code($code) { $code = str_replace("<br />", "", $code); //Om te zorgen voor goede weergave ivm. nl2br bij ubb(); $code = xhtmlcode($code); //Om font te veranderen in <span style='.... en lettertype als verdana $regels = explode("<br />", $code); $nummers = count($regels); $blok = "<table bgcolor='#f1f5f6' cellpadding='3' cellspacing='0' style='border:1px solid #3f7082;' width='506'> <tr> <td width='100%'><div style='overflow:auto; overflow-x:scroll; width:500px;'> <table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse;' width='100%'> <tr> <td width='100%' colspan='2' bgcolor='#deecf1' style='font-family:Verdana; font-size:11px; font-weight:bold; padding:2px;'>C o d e</td> </tr> <tr> <td width='25' nowrap valign='top' bgcolor='#f1f5f6' style='font-family:Verdana; font-size:11px;'>"; for($i=1; $i<=$nummers; $i++) { $blok .= $i."<br />\n"; } $blok .= " </td> <td width='100%' nowrap valign='top' bgcolor='#f1f5f6' style='font-size:12px;'>".$code."</td> </tr> </table> </div></td> </tr> </table>"; return $blok; } if(!isset($_POST['submit'])) { echo "<form method='post'> <textarea style='width:506px; height:150px;' name='code'></textarea><br /> <input type='submit' name='submit' value='Highlight code!' /> </form>"; } else { echo "<form method='post'> <input type='submit' name='submit' value='Highlight code!' /> </form><br />"; echo ubb ($_POST['code']); } ?>
Nu heb ik een probleem:
Als je bijvoorbeeld [code*][b*]test[/b*][/code*] doet, dan zet hij die [b*] en [/b*] om in resp. <b> en </b>.
Hoe kan ik ervoor zorgen dat hij die dan over slaat?
Dus dat hij gewoon [b*]test[/b*] laat zien in de code-box?
BVD,
Lennard.
Edit:
Zie www.lennardesveld.com/ubb.php voor beter weergave.
Medewerker edit:
Gebruik de [code ]-tags .
|