Minimalistic BBcode script
| From: | DZ | Date: | Sat, 14 Jun 2003 13:53:45 +0000 |
| Subject: | Minimalistic BBcode script | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-151476@lists.php.net to get a copy of this message | ||
Hello,
I found one minimalistic BBcode script, but it doesnt work.
Warning: Unknown modifier '1' in f:\_php\_f\bb-code\test.php on line 32
line 32 is such:
$t = preg_replace_callback( '/[('.$atag.')(=(.*))?](.*)[/1]/isU',
'nc', $s);
How to get work it?
Source is only 40 lines:
<?php
$tagid = array(
'b' => '<b>%s</b>',
'u' => '<u>%s</u>',
'i' => '<i>%s</i>',
'tsitaat' =>
'<blockquote><small><b>Tsitaat</b>:<hr>%s<hr></small></blockquote>',
'url' => '<a href="%s">%s</a>',
'mail' => '<a href="mailto:%s">%s</a>',
'img' => '<img src="%s" alt="%s">',
'code' => '<font color="green">%s</font>',
'kood' => '<font color="green">%s</font>',
'color' => '<font color="%s">%s</font>',
'size' => '<font size="%s">%s</font>'
);
$atag = join( '|', array_keys( $tagid));
/*
print '<p>allowed tags:</p>';
foreach( $tagid as $key => $value) {
echo "<b>$key</b><br>n";
}
*/
function nc( $s){
if ( $s[1] ) $s[4] = nk( $s[4]);
global $tagid;
return $s[1]?sprintf($tagid[$s[1]],(!empty($s[3])?$s[3]:$s[4]),$s[4]):$s[0];
}
function nk( $s){
global $atag;
$t = preg_replace_callback( '/[('.$atag.')(=(.*))?](.*)[/1]/isU',
'nc', $s);
return $t;
}
$text = "[b]bold text [i]mixed with[/b] italic[/i]";
echo nl2br( nk( htmlspecialchars( $text, ENT_NOQUOTES)));
?>