[PHP] Minimalistic BBcode script

2003-06-14 Thread DZ
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' = 'blockquotesmallbTsitaat/b:hr%shr/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 'pallowed tags:/p';
foreach( $tagid as $key = $value) {
echo b$key/bbrn;
}
*/

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)));

?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Minimalistic BBcode script

2003-06-14 Thread Jason Wong
On Saturday 14 June 2003 21:53, DZ wrote:

 I found one minimalistic BBcode script, but it doesnt work.

Wouldn't it be better to find some code which *did* 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?

I don't know how to get it to work, but doing

$t = preg_replace_callback( '#[('.$atag.')(=(.*))?](.*)[/1]#isU', 'nc', $s);

should at least get rid of the warning.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Your love life will be happy and harmonious.
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php