Zend_Markup-Getting-Started.xml 2.9 KB

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