(No version information available, might be only in CVS)
bbcode_add_smiley — Adds a smiley to the parser
Adds a smiley to the parser
BBCode_Container resource, returned by bbcode_create().
The string that will be replaced when found.
The string that replace smiley when found.
如果成功则返回 TRUE,失败则返回 FALSE。
Example#1 bbcode_add_smiley() usage example
<?php
/*
* Prepare the rule set
*/
$arrayBBCode=array(
''=> array('type'=>BBCODE_TYPE_ROOT,
'childs'=>'!i'),
'b'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<b>',
'close_tag'=>'</b>'),
'u'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<u>',
'close_tag'=>'</u>',
'flags'=>BBCODE_FLAGS_SMILEYS_OFF),
'i'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<i>',
'close_tag'=>'</i>',
'childs'=>'b'),
);
/*
* Parsed Text
*/
$text=<<<EOF
[i] No parse Test [/i] :)
[b] Parsed, with smiley :( [/b]
[u] Parsed, with no smiley :D [/u]
EOF;
/*
* Init the parser
*/
$BBHandler=bbcode_create($arrayBBCode);
/*
* Add Smiley rules to parser
*/
bbcode_add_smiley($BBHandler, ":)", "<img src=\"smiley.png\" alt=\":)\" />");
bbcode_add_smiley($BBHandler, ":(", "<img src=\"sad.png\" alt=\":(\" />");
bbcode_add_smiley($BBHandler, ":D", "<img src=\"happy.png\" alt=\":D\" />");
bbcode_add_smiley($BBHandler, ":p", "<img src=\"tong.png\" alt=\":p\" />");
bbcode_add_smiley($BBHandler, ":|", "<img src=\"special.png\" alt=\":|\" />");
bbcode_add_smiley($BBHandler, ":6:", "<img src=\"six.png\" alt=\":6:\" />");
/*
* Parse the text
*/
echo bbcode_parse($BBHandler,$text);
?>
上例将输出:
[i] No parse Test [/i] <img src="smiley.png" alt=":)" /> <b> Parsed, with smiley <img src="sad.png" alt=":(" /> </b> <u> Parsed, with no smiley :D </u>