Manuel PHP

bbcode_create

(PECL bbcode:0.9.0-0.9.1)

bbcode_create — Create a BBCode Resource

Description

resource bbcode_create ([ array $bbcode_initial_tags ] )

This function returns a new BBCode Resource used to parse BBCode strings.

Liste de paramètres

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 child 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 child for the tag.
  • parent optional - List of accepted child for the tag. The format of the list is a comma separated string.

Valeurs de retour

Returns a BBCode_Container

Exemples

Example#1 bbcode_create() example

  1. <?php
  2. $arrayBBCode=array( 
  3.    ''=>      array('type'=>BBCODE_TYPE_ROOT, 'childs'=>'!i'), 
  4.    'i'=>      array('type'=>BBCODE_TYPE_NOARG, 'open_tag'=>'<i>', 
  5.                'close_tag'=>'</i>', 'childs'=>'b'), 
  6.    'url'=>   array('type'=>BBCODE_TYPE_OPTARG, 
  7.                'open_tag'=>'<a href="{PARAM}">', 'close_tag'=>'</a>', 
  8.                'default_arg'=>'{CONTENT}', 
  9.                'childs'=>'b,i'), 
  10.    'img'=>   array('type'=>BBCODE_TYPE_NOARG, 
  11.                'open_tag'=>'<img src="', 'close_tag'=>'" />', 
  12.                'childs'=>''), 
  13.    'b'=>      array('type'=>BBCODE_TYPE_NOARG, 'open_tag'=>'<b>', 
  14.                'close_tag'=>'</b>'),  
  15. );  
  16. $text=<<<EOF
  17. Bold Text
  18. Italic Text
  19. [url]http://www.php.net/[/url]
  20. [url=http://pecl.php.net/]Content Text[/url]
  21. [img]http://static.php.net/www.php.net/images/php.gif[/img]
  22. [url=http://www.php.net/]
  23. [img]http://static.php.net/www.php.net/images/php.gif[/img]
  24. [/url]
  25. EOF;  
  26. $BBHandler=bbcode_create($arrayBBCode);  
  27. echo bbcode_parse($BBHandler,$text);  
  28. ?> 

L'exemple ci-dessus va afficher :

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


Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Breizh Blog