/www/caches/scripts/StringParcer/doc/en/chapter9.html
HTML | 168 lines | 167 code | 0 blank | 1 comment | 0 complexity | afb3920b16d6500fd13a35df479ea2b3 MD5 | raw file
Possible License(s): MIT
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <meta http-equiv="Content-Language" content="en">
- <title>StringParser_BBCode class documentation</title>
- <meta name="author" content="Christian Seiler">
- <link rel="stylesheet" href="../css/print.css" type="text/css" media="print">
- <link rel="stylesheet" href="../css/screen.css" type="text/css" media="screen, projection">
- </head>
- <body id="doku">
- <div id="container">
- <h1><span><code>StringParser_<abbr title="Bulletin Board Code">BBCode</abbr></code> class</span> documentation</h1>
- <ul id="mainmenu">
- <li><a href="http://www.christian-seiler.de/projekte/php/bbcode/index_en.html">Project homepage</a></li>
- <li><a href="chapter1.html">Documentation</a></li>
- <li><a href="../phpdoc/index.html">PHPDOC Documentation</a></li>
- <li><a href="http://www.christian-seiler.de/projekte/php/bbcode/download_en.html">Download</a></li>
- <li><a href="../de/kapitel9.html">Diese Seite auf Deutsch</a></li>
- </ul>
- <ul id="menu">
- <li><a href="chapter1.html">1. Introduction</a>
- <ul>
- <li><a href="chapter1.html#general">1.1 General</a></li>
- <li><a href="chapter1.html#nesting">1.2 Nesting</a></li>
- <li><a href="chapter1.html#special">1.3 Special codes</a></li>
- </ul></li>
- <li><a href="chapter2.html">2. Defining own <abbr>BBCode</abbr></a>
- <ul>
- <li><a href="chapter2.html#including">2.1 Including the class</a></li>
- <li><a href="chapter2.html#first">2.2 The first code</a></li>
- <li><a href="chapter2.html#processing_types">2.3 Processing types</a></li>
- <li><a href="chapter2.html#parsing">2.4 Parsing text</a></li>
- </ul></li>
- <li><a href="chapter3.html">3. Parser functions</a>
- <ul>
- <li><a href="chapter3.html#task">3.1 Task of parser functions</a></li>
- <li><a href="chapter3.html#content_types">3.2 Relevance of content types</a></li>
- <li><a href="chapter3.html#registration">3.3 Registration of parser functions</a></li>
- </ul></li>
- <li><a href="chapter4.html">4. Callback functions</a>
- <ul>
- <li><a href="chapter4.html#processing_types">4.1 Processing types that need callback functions</a></li>
- <li><a href="chapter4.html#prototype">4.2 Prototype of a callback function</a></li>
- <li><a href="chapter4.html#example">4.3 Example for a callback function that replaces links</a></li>
- <li><a href="chapter4.html#revalidation">4.4 Revalidation on close tag occurrence</a></li>
- </ul></li>
- <li><a href="chapter5.html">5. Filters</a>
- <ul>
- <li><a href="chapter5.html#types">5.1 Filter types</a></li>
- <li><a href="chapter5.html#defining">5.2 Defining filters</a></li>
- </ul></li>
- <li><a href="chapter6.html">6. Flags to control the behaviour of the class</a>
- <ul>
- <li><a href="chapter6.html#general">6.1 General</a></li>
- <li><a href="chapter6.html#flags">6.2 List of all flags</a></li>
- <li><a href="chapter6.html#global">6.2 Global flags</a></li>
- </ul></li>
- <li><a href="chapter7.html">7. Limiting the amount of occurrences</a>
- <ul>
- <li><a href="chapter7.html#grouping">7.1 Grouping codes</a></li>
- <li><a href="chapter7.html#limits">7.2 Setting limits</a></li>
- </ul></li>
- <li><a href="chapter8.html">8. Paragraph handling</a>
- <ul>
- <li><a href="chapter8.html#general">8.1 General</a></li>
- <li><a href="chapter8.html#activating">8.2 Activating paragraph handling</a></li>
- <li><a href="chapter8.html#further">8.3 Further possibilities</a></li>
- </ul></li>
- <li><a href="chapter9.html">9. Examples</a>
- <ul>
- <li><a href="chapter9.html#example">9.1 Simple example</a></li>
- <!-- <li><a href="chapter9.html#complex">9.2 More complex example</a></li> -->
- </ul></li>
- <li><a href="chapter10.html">10. Miscellaneous</a>
- <ul>
- <li><a href="chapter10.html#faq">10.1 Frequently asked questions</a></li>
- <li><a href="chapter10.html#internals">10.2 Useful internals</a></li>
- </ul></li>
- </ul>
- <div id="content"><h2>9. Examples</h2>
- <h3 id="example"><a name="example">9.1 Example</a></h3>
- <p class="php"><code>// Unify line breaks of different operating systems<br>
- function convertlinebreaks ($text) {<br>
- return preg_replace ("/\015\012|\015|\012/", "\n", $text);<br>
- }<br>
- <br>
- // Remove everything but the newline charachter<br>
- function bbcode_stripcontents ($text) {<br>
- return preg_replace ("/[^\n]/", '', $text);<br>
- }<br>
- <br>
- function do_bbcode_url ($action, $attributes, $content, $params, $node_object) {<br>
- if (!isset ($attributes['default'])) {<br>
- $url = $content;<br>
- $text = htmlspecialchars ($content);<br>
- } else {<br>
- $url = $attributes['default'];<br>
- $text = $content;<br>
- }<br>
- if ($action == 'validate') {<br>
- if (substr ($url, 0, 5) == 'data:' || substr ($url, 0, 5) == 'file:'<br>
- || substr ($url, 0, 11) == 'javascript:' || substr ($url, 0, 4) == 'jar:') {<br>
- return false;<br>
- }<br>
- return true;<br>
- }<br>
- return '<a href="'.htmlspecialchars ($url).'">'.$text.'</a>';<br>
- }<br>
- <br>
- // Function to include images<br>
- function do_bbcode_img ($action, $attributes, $content, $params, $node_object) {<br>
- if ($action == 'validate') {<br>
- if (substr ($content, 0, 5) == 'data:' || substr ($content, 0, 5) == 'file:'<br>
- || substr ($content, 0, 11) == 'javascript:' || substr ($content, 0, 4) == 'jar:') {<br>
- return false;<br>
- }<br>
- return true;<br>
- }<br>
- return '<img src="'.htmlspecialchars($content).'" alt="">';<br>
- }<br>
- <br>
- $bbcode = new StringParser_BBCode ();<br>
- $bbcode->addFilter (STRINGPARSER_FILTER_PRE, 'convertlinebreaks');<br>
- <br>
- $bbcode->addParser (array ('block', 'inline', 'link', 'listitem'), 'htmlspecialchars');<br>
- $bbcode->addParser (array ('block', 'inline', 'link', 'listitem'), 'nl2br');<br>
- $bbcode->addParser ('list', 'bbcode_stripcontents');<br>
- <br>
- $bbcode->addCode ('b', 'simple_replace', null, array ('start_tag' => '<b>', 'end_tag' => '</b>'),<br>
- 'inline', array ('listitem', 'block', 'inline', 'link'), array ());<br>
- $bbcode->addCode ('i', 'simple_replace', null, array ('start_tag' => '<i>', 'end_tag' => '</i>'),<br>
- 'inline', array ('listitem', 'block', 'inline', 'link'), array ());<br>
- $bbcode->addCode ('url', 'usecontent?', 'do_bbcode_url', array ('usecontent_param' => 'default'),<br>
- 'link', array ('listitem', 'block', 'inline'), array ('link'));<br>
- $bbcode->addCode ('link', 'callback_replace_single', 'do_bbcode_url', array (),<br>
- 'link', array ('listitem', 'block', 'inline'), array ('link'));<br>
- $bbcode->addCode ('img', 'usecontent', 'do_bbcode_img', array (),<br>
- 'image', array ('listitem', 'block', 'inline', 'link'), array ());<br>
- $bbcode->addCode ('bild', 'usecontent', 'do_bbcode_img', array (),<br>
- 'image', array ('listitem', 'block', 'inline', 'link'), array ());<br>
- $bbcode->setOccurrenceType ('img', 'image');<br>
- $bbcode->setOccurrenceType ('bild', 'image');<br>
- $bbcode->setMaxOccurrences ('image', 2);<br>
- $bbcode->addCode ('list', 'simple_replace', null, array ('start_tag' => '<ul>', 'end_tag' => '</ul>'),<br>
- 'list', array ('block', 'listitem'), array ());<br>
- $bbcode->addCode ('*', 'simple_replace', null, array ('start_tag' => '<li>', 'end_tag' => '</li>'),<br>
- 'listitem', array ('list'), array ());<br>
- $bbcode->setCodeFlag ('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL);<br>
- $bbcode->setCodeFlag ('*', 'paragraphs', true);<br>
- $bbcode->setCodeFlag ('list', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT);<br>
- $bbcode->setCodeFlag ('list', 'opentag.before.newline', BBCODE_NEWLINE_DROP);<br>
- $bbcode->setCodeFlag ('list', 'closetag.before.newline', BBCODE_NEWLINE_DROP);<br>
- $bbcode->setRootParagraphHandling (true);<br>
- <br>
- $text = '[b]This is a test![/b]';<br>
- echo $bbcode->parse ($text);</code></p>
- <hr>
- <ul>
- <li>Next: <a href="chapter10.html">10. Miscellaneous</a></li>
- <li>Previous: <a href="chapter8.html">8. Paragraph handling</a></li>
- </ul>
- </div>
- <p id="footer">This is the documentation for the <code>StringParser_BBCode</code> class version <em>0.3.3</em><br>
- Author: Christian Seiler, <a href="mailto:webmaster@christian-seiler.de">webmaster@christian-seiler.de</a></p>
- </div>
- </body>
- </html>