Re: Minimalistic BBcode script

From: Date: Sun, 15 Jun 2003 15:01:21 +0000
Subject: Re: Minimalistic BBcode script
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-151582@lists.php.net to get a copy of this message
$text=preg_replace("#\[([bisu])\](.*?)\[/\\1\]#i","<\\1>\\2</\\1>",$text); "Dz" <dontzpam@hot.ee> skrev i meddelandet news:php.general-151476@news.php.net... > 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))); > > ?>

« previous php.general (#151582) next »