Zend_Markup-Getting-Started.xml 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.markup.getting-started">
  4. <title>Getting Started With Zend_Markup</title>
  5. <para>
  6. This guide to get you started with <classname>Zend_Markup</classname> uses the BBCode parser
  7. and <acronym>HTML</acronym> renderer. The priciples discussed can be adapted to other
  8. parsers and renderers.
  9. </para>
  10. <example id="zend.markup.getting-started.basic-usage">
  11. <title>Basic Zend_Markup Usage</title>
  12. <para>
  13. We will first instantiate a <classname>Zend_Markup_Renderer_Html</classname> object
  14. using the <methodname>Zend_Markup::factory()</methodname> method. This will also create
  15. a <classname>Zend_Markup_Parser_Bbcode</classname> object which will be added to the
  16. renderer object.
  17. </para>
  18. <para>
  19. Afther that, we will use the <methodname>render()</methodname> method to convert a piece
  20. of BBCode to <acronym>HTML</acronym>.
  21. </para>
  22. <programlisting language="php"><![CDATA[
  23. // Creates instance of Zend_Markup_Renderer_Html,
  24. // with Zend_Markup_Parser_BbCode as its parser
  25. $bbcode = Zend_Markup::factory('Bbcode');
  26. echo $bbcode->render('[b]bold text[/b] and [i]cursive text[/i]');
  27. // Outputs: '<strong>bold text</strong> and <em>cursive text</em>'
  28. ]]></programlisting>
  29. </example>
  30. <example id="zend.markup.getting-started.complicated-example">
  31. <title>A more complicated example of Zend_Markup</title>
  32. <para>
  33. This time, we will do exactly the same as above, but with more complicated BBCode
  34. markup.
  35. </para>
  36. <programlisting language="php"><![CDATA[
  37. $bbcode = Zend_Markup::factory('Bbcode');
  38. $input = <<<EOT
  39. [list]
  40. [*]Zend Framework
  41. [*]Foobar
  42. [/list]
  43. EOT;
  44. echo $bbcode->render($input);
  45. /*
  46. Should output something like:
  47. <ul>
  48. <li>Zend Framework</li>
  49. <li>Foobar</li>
  50. </ul>
  51. */
  52. ]]></programlisting>
  53. </example>
  54. <example id="zend.markup.getting-started.incorrect-input">
  55. <title>Processing incorrect input</title>
  56. <para>
  57. Besides simply parsing and rendering markup such as BBCode,
  58. <classname>Zend_Markup</classname> is also able to handle incorrect input. Most BBCode
  59. processors are not able to render all input to <acronym>XHTML</acronym> valid output.
  60. <classname>Zend_Markup</classname> corrects input that is nested incorrectly, and also
  61. closes tags that were not closed:
  62. </para>
  63. <programlisting language="php"><![CDATA[
  64. $bbcode = Zend_Markup::factory('Bbcode');
  65. echo $bbcode->render('some [i]wrong [b]sample [/i] text');
  66. // Note that the '[b]' tag is never closed, and is also incorrectly
  67. // nested; regardless, Zend_Markup renders it correctly as:
  68. // some <em>wrong <strong>sample </strong></em><strong> text</strong>
  69. ]]></programlisting>
  70. </example>
  71. </sect1>