File: Zend_Markup-Getting-Started.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (86 lines) | stat: -rw-r--r-- 2,953 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.markup.getting-started">
    <title>Getting Started With Zend_Markup</title>

    <para>
        This guide to get you started with <classname>Zend_Markup</classname> uses the BBCode parser
        and <acronym>HTML</acronym> renderer. The priciples discussed can be adapted to other
        parsers and renderers.
    </para>

    <example id="zend.markup.getting-started.basic-usage">
        <title>Basic Zend_Markup Usage</title>

        <para>
            We will first instantiate a <classname>Zend_Markup_Renderer_Html</classname> object
            using the <methodname>Zend_Markup::factory()</methodname> method. This will also create
            a <classname>Zend_Markup_Parser_Bbcode</classname> object which will be added to the
            renderer object.
        </para>

        <para>
            Afther that, we will use the <methodname>render()</methodname> method to convert a piece
            of BBCode to <acronym>HTML</acronym>.
        </para>

        <programlisting language="php"><![CDATA[
// Creates instance of Zend_Markup_Renderer_Html,
// with Zend_Markup_Parser_BbCode as its parser
$bbcode = Zend_Markup::factory('Bbcode');

echo $bbcode->render('[b]bold text[/b] and [i]cursive text[/i]');
// Outputs: '<strong>bold text</strong> and <em>cursive text</em>'
]]></programlisting>
    </example>

    <example id="zend.markup.getting-started.complicated-example">
        <title>A more complicated example of Zend_Markup</title>

        <para>
            This time, we will do exactly the same as above, but with more complicated BBCode
            markup.
        </para>

        <programlisting language="php"><![CDATA[
$bbcode = Zend_Markup::factory('Bbcode');

$input = <<<EOT
[list]
[*]Zend Framework
[*]Foobar
[/list]
EOT;

echo $bbcode->render($input);
/*
Should output something like:
<ul>
<li>Zend Framework</li>
<li>Foobar</li>
</ul>
*/
]]></programlisting>
    </example>

    <example id="zend.markup.getting-started.incorrect-input">
        <title>Processing incorrect input</title>

        <para>
            Besides simply parsing and rendering markup such as BBCode,
            <classname>Zend_Markup</classname> is also able to handle incorrect input. Most BBCode
            processors are not able to render all input to <acronym>XHTML</acronym> valid output.
            <classname>Zend_Markup</classname> corrects input that is nested incorrectly, and also
            closes tags that were not closed:
        </para>

        <programlisting language="php"><![CDATA[
$bbcode = Zend_Markup::factory('Bbcode');

echo $bbcode->render('some [i]wrong [b]sample [/i] text');
// Note that the '[b]' tag is never closed, and is also incorrectly
// nested; regardless, Zend_Markup renders it correctly as:
// some <em>wrong <strong>sample </strong></em><strong> text</strong>
]]></programlisting>
    </example>
</sect1>