|
53 | 53 | echo '<h2>Example 1</h2>';
|
54 | 54 | echo 'Add the attribute <code>class="cell"</code> to all <code><td></code> elements:';
|
55 | 55 |
|
| 56 | + echo '<pre><code> |
| 57 | +<?php |
| 58 | +
|
| 59 | +echo html5qp($html, "td") |
| 60 | +->attr("class", "cell") |
| 61 | +->top("table") |
| 62 | +->html() |
| 63 | +</code></pre>'; |
| 64 | + |
| 65 | + echo 'This will output the following HTML:'; |
| 66 | + |
| 67 | + echo '<pre><code>'; |
| 68 | + |
| 69 | + echo htmlspecialchars( |
| 70 | + html5qp($html, 'td') |
| 71 | + ->attr('class', 'cell') |
| 72 | + ->top('table') // jump back up the DOM to the table |
| 73 | + ->html() // get get HTML of the table |
| 74 | + ); |
| 75 | + |
| 76 | + echo '</code></pre>'; |
| 77 | + |
| 78 | + echo 'If you want to output a valid HTML document, use <code>top()</code> without an argument:'; |
| 79 | + |
56 | 80 | echo '<pre><code>';
|
57 | 81 |
|
58 | 82 | echo htmlspecialchars(
|
59 | 83 | html5qp($html, 'td')
|
60 | 84 | ->attr('class', 'cell')
|
61 |
| - ->top() // return to <html> tag |
62 |
| - ->innerHTML5() // get mark-up without <html>. Use ->html5() to return a valid HTML document (Doctype and all) |
| 85 | + ->top() |
| 86 | + ->html() |
63 | 87 | );
|
64 | 88 |
|
65 | 89 | echo '</code></pre>';
|
66 | 90 |
|
67 | 91 | echo '<h2>Example 2</h2>';
|
68 |
| - echo 'Use <code>html5qp($html)->find(\'#row2 > td:nth-child(2)\')->text();</code> to display the contents of the second <code><td></code> in the second <code><tr></code>: <br><strong>'; |
| 92 | + echo 'Find and output the text of the second cell in the second row of the table:'; |
69 | 93 |
|
70 |
| - echo html5qp($html) |
| 94 | + $text = html5qp($html) |
71 | 95 | ->find('#row2 > td:nth-child(2)')
|
72 | 96 | ->text();
|
73 | 97 |
|
74 |
| - echo '</strong>'; |
| 98 | + echo '<pre><code> |
| 99 | +<?php |
| 100 | +
|
| 101 | +echo html5qp($html) |
| 102 | +->find("#row2 > td:nth-child(2)") |
| 103 | +->text(); |
| 104 | +
|
| 105 | +// Result: '. $text. ' |
| 106 | +</code></pre>'; |
75 | 107 |
|
76 | 108 | echo '<h2>Example 3</h2>';
|
77 |
| - echo 'Append another row to the HTML and output the results:'; |
| 109 | + echo 'Append an additional row at the end of the table:'; |
| 110 | + echo '<pre><code> |
| 111 | +<?php |
| 112 | +
|
| 113 | +echo html5qp($html, "td") |
| 114 | +->after("<tr><td>seven</td><td>eight</td><td>nine</td></tr>") |
| 115 | +->top("table") |
| 116 | +->html() |
| 117 | +</code></pre>'; |
| 118 | + |
| 119 | + echo 'This will output the following HTML:'; |
| 120 | + |
78 | 121 | echo '<code><pre>';
|
79 | 122 |
|
80 | 123 | echo htmlspecialchars(
|
81 | 124 | html5qp($html, 'tr:last')
|
82 | 125 | ->after("\n\n\t<tr>\n\t\t<td>seven</td>\n\t\t<td>eight</td>\n\t\t<td>nine</td>\n\t</tr>")
|
83 |
| - ->top() // return to <html> tag |
84 |
| - ->innerHTML5() // get mark-up without <html>. Use ->html5() to return a valid HTML document (Doctype and all) |
| 126 | + ->top("table") |
| 127 | + ->html() |
85 | 128 | );
|
86 | 129 |
|
87 | 130 | echo '</pre></code>';
|
|
93 | 136 | echo '<h2>Example 1</h2>';
|
94 | 137 | echo 'Add the attribute <code>class="item"</code> to all <code><desc></code> elements:';
|
95 | 138 |
|
| 139 | + echo '<pre><code> |
| 140 | +<?php |
| 141 | +
|
| 142 | +echo qp($xml, "desc") |
| 143 | +->attr("class", "item) |
| 144 | +->top() // return to the <categories> tag |
| 145 | +->xml(); // output a valid XML document. |
| 146 | +</code></pre>'; |
| 147 | + |
| 148 | + echo 'This will output the following XML:'; |
| 149 | + |
96 | 150 | echo '<pre><code>';
|
97 | 151 |
|
98 | 152 | echo htmlspecialchars(
|
99 | 153 | qp($xml, 'desc')
|
100 | 154 | ->attr('class', 'item')
|
101 | 155 | ->top() // return to the <categories> tag
|
102 |
| - ->xml() // output a valid XML document. Use ->innerXML() to get the contents of <categories /> instead. |
| 156 | + ->xml() // output a valid XML document |
103 | 157 | );
|
104 | 158 |
|
105 | 159 | echo '</code></pre>';
|
106 | 160 |
|
| 161 | + echo 'You can omit the XML declaration by setting the first argument to true: <code>->xml(true)</code>.'; |
| 162 | + |
107 | 163 | echo '<h2>Example 2</h2>';
|
108 |
| - echo 'Use <code>qp($xml)->find(\'categories > category:nth-child(3) desc\')->text();</code> to display the contents of the third <code><desc></code>: <br><strong>'; |
| 164 | + echo 'Find and output the text of the third <code><desc></code> tag:'; |
109 | 165 |
|
110 |
| - echo qp($xml) |
| 166 | + $text = qp($xml) |
111 | 167 | ->find('categories > category:nth-child(3) desc')
|
112 | 168 | ->text();
|
113 | 169 |
|
114 |
| - echo '</strong>'; |
| 170 | + echo '<pre><code> |
| 171 | +<?php |
| 172 | +
|
| 173 | +echo qp($xml) |
| 174 | +->find("categories > category:nth-child(3) desc") |
| 175 | +->text(); |
| 176 | + |
| 177 | + // Result: '.$text.' |
| 178 | +</code></pre>'; |
115 | 179 |
|
116 | 180 | echo '<h2>Example 3</h2>';
|
117 |
| - echo 'Append another category to the XML and output the results:'; |
| 181 | + echo 'Append a category at the end of the group:'; |
| 182 | + echo '<pre><code> |
| 183 | +<?php |
| 184 | +
|
| 185 | +echo qp($xml, "category:last") |
| 186 | +->after("<category name=\'Appended\'><desc>The appended node...</desc></category>") |
| 187 | +->top() |
| 188 | +->xml() |
| 189 | +</code></pre>'; |
| 190 | + |
| 191 | + echo 'This will output the following HTML:'; |
| 192 | + |
118 | 193 | echo '<code><pre>';
|
119 | 194 |
|
120 | 195 | echo htmlspecialchars(
|
121 | 196 | qp($xml, 'category:last')
|
122 |
| - ->after("\n\n\t<category nam=\"Appended\">\n\t\t<desc>The appended node...</desc>\n\t</category>") |
| 197 | + ->after("\n\n\t<category name=\"Appended\">\n\t\t<desc>The appended node...</desc>\n\t</category>") |
123 | 198 | ->top()
|
124 | 199 | ->xml()
|
125 | 200 | );
|
|
0 commit comments