bbcode_create
(PECL bbcode >= 0.9.0)
bbcode_create — Create a BBCode Resource
Description
$bbcode_initial_tags
= NULL
] ) : resourceThis function returns a new BBCode Resource used to parse BBCode strings.
Parameters
-
bbcode_initial_tags
-
An associative array containing the tag names as keys and parameters required to correctly parse BBCode as their value. The following key/value pairs are supported:
- flags optional - a flag set based on the BBCODE_FLAGS_* constants.
- type required - an int indicating the type of tag. Use the BBCODE_TYPE_* constants.
- open_tag required - the HTML replacement string for the open tag.
- close_tag required - the HTML replacement string for the close tag.
- default_arg optional - use this value as the default argument if none is provided and tag_type is of type OPTARG.
- content_handling optional - Gives the callback used for modification of the content. Object Oriented Notation supported only since 0.10.1 callback prototype is string name(string $content, string $argument)
- param_handling optional - Gives the callback used for modification of the argument. Object Oriented Notation supported only since 0.10.1 callback prototype is string name(string $content, string $argument)
- childs optional - List of accepted children for the tag. The format of the list is a comma separated string. If the list starts with ! it will be the list of rejected children for the tag.
- parent optional - List of accepted parents for the tag. The format of the list is a comma separated string.
Examples
Example #1 bbcode_create() example
<?php
$arrayBBCode=array(
''=> array('type'=>BBCODE_TYPE_ROOT, 'childs'=>'!i'),
'i'=> array('type'=>BBCODE_TYPE_NOARG, 'open_tag'=>'<i>',
'close_tag'=>'</i>', 'childs'=>'b'),
'url'=> array('type'=>BBCODE_TYPE_OPTARG,
'open_tag'=>'<a href="https://www.gaudry.be/en/php-rf-{PARAM}">', 'close_tag'=>'</a>',
'default_arg'=>'{CONTENT}',
'childs'=>'b,i'),
'img'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<img src="https://www.gaudry.be/http://php.net/', 'close_tag'=>'" />',
'childs'=>''),
'b'=> array('type'=>BBCODE_TYPE_NOARG, 'open_tag'=>'<b>',
'close_tag'=>'</b>'),
);
$text=<<<EOF
[b]Bold Text[/b]
[i]Italic Text[/i]
[url]http://www.php.net/[/url]
[url=http://pecl.php.net/][b]Content Text[/b][/url]
[img]http://static.php.net/www.php.net/images/php.gif[/img]
[url=http://www.php.net/]
[img]http://static.php.net/www.php.net/images/php.gif[/img]
[/url]
EOF;
$BBHandler=bbcode_create($arrayBBCode);
echo bbcode_parse($BBHandler,$text);
?>
The above example will output:
<b>Bold Text</b> [i]Italic Text[/i] <a href="http://www.php.net/">http://www.php.net/</a> <a href="http://pecl.php.net/"><b>Content Text</b></a> <img src="http://static.php.net/www.php.net/images/php.gif" /> <a href="http://www.php.net/"> [img]http://static.php.net/www.php.net/images/php.gif[/img] </a>
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-bbcode-create.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.