1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.markup.getting-started">
4 <title>Getting Started With Zend_Markup</title>
7 This guide to get you started with <classname>Zend_Markup</classname> uses the BBCode parser
8 and <acronym>HTML</acronym> renderer. The priciples discussed can be adapted to other
12 <example id="zend.markup.getting-started.basic-usage">
13 <title>Basic Zend_Markup Usage</title>
16 We will first instantiate a <classname>Zend_Markup_Renderer_Html</classname> object
17 using the <methodname>Zend_Markup::factory()</methodname> method. This will also create
18 a <classname>Zend_Markup_Parser_Bbcode</classname> object which will be added to the
23 Afther that, we will use the <methodname>render()</methodname> method to convert a piece
24 of BBCode to <acronym>HTML</acronym>.
27 <programlisting language="php"><![CDATA[
28 // Creates instance of Zend_Markup_Renderer_Html,
29 // with Zend_Markup_Parser_BbCode as its parser
30 $bbcode = Zend_Markup::factory('Bbcode');
32 echo $bbcode->render('[b]bold text[/b] and [i]cursive text[/i]');
33 // Outputs: '<strong>bold text</strong> and <em>cursive text</em>'
37 <example id="zend.markup.getting-started.complicated-example">
38 <title>A more complicated example of Zend_Markup</title>
41 This time, we will do exactly the same as above, but with more complicated BBCode
45 <programlisting language="php"><![CDATA[
46 $bbcode = Zend_Markup::factory('Bbcode');
55 echo $bbcode->render($input);
57 Should output something like:
59 <li>Zend Framework</li>
66 <example id="zend.markup.getting-started.incorrect-input">
67 <title>Processing incorrect input</title>
70 Besides simply parsing and rendering markup such as BBCode,
71 <classname>Zend_Markup</classname> is also able to handle incorrect input. Most BBCode
72 processors are not able to render all input to <acronym>XHTML</acronym> valid output.
73 <classname>Zend_Markup</classname> corrects input that is nested incorrectly, and also
74 closes tags that were not closed:
77 <programlisting language="php"><![CDATA[
78 $bbcode = Zend_Markup::factory('Bbcode');
80 echo $bbcode->render('some [i]wrong [b]sample [/i] text');
81 // Note that the '[b]' tag is never closed, and is also incorrectly
82 // nested; regardless, Zend_Markup renders it correctly as:
83 // some <em>wrong <strong>sample </strong></em><strong> text</strong>