manual_api.htm
11.2 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHP Simple HTML DOM Parser: API Reference</title>
<link href="css/default.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1><a name="top"></a>PHP Simple HTML DOM Parser Manual</h1>
<div id="content">
<h2>Index</h2>
<ul>
<li><a href="manual.htm">Back</a></li>
<li><a href="#api">API Reference</a></li>
<li><a href="#camel">Camel naming conventions</a></li>
</ul>
<a name="api"></a>
<h2>API Reference</h2>
<a class="top" href="#top">Top</a>
<div class="code"> <strong>Helper</strong> functions
<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<th width="320">Name</th>
<th>Description</th>
</tr>
<tr>
<td><span class="returns">object</span> str_get_html ( <span class="var">string $content</span> )</td>
<td class="description">Creates a DOM object from a string.</td>
</tr>
<tr>
<td><span class="returns">object</span> file_get_html ( <span class="var">string $filename</span> )</td>
<td class="description">Creates a DOM object from a file or a URL.</td>
</tr>
</table>
<br>
<strong>DOM</strong> methods & properties <br>
<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<th width="320"> Name</th>
<th> Description</th>
</tr>
<tr>
<td>
<div class="returns">void</div>
__construct ( <span class="var">[string $filename]</span> )</td>
<td class="description">Constructor, set the filename parameter will automatically load the contents, either text or file/url.</td>
</tr>
<tr>
<td>
<div class="returns">string</div>
plaintext</td>
<td class="description">Returns the contents extracted from HTML.</td>
</tr>
<tr>
<td>
<div class="returns">void</div>
clear ()</td>
<td class="description">Clean up memory.</td>
</tr>
<tr>
<td>
<div class="returns">void</div>
load ( <span class="var">string $content </span>)</td>
<td class="description"> Load contents from a <strong>string</strong>. </td>
</tr>
<tr>
<td>
<div class="returns">string</div>
save ( <span class="var">[string $filename]</span> )</td>
<td class="description">Dumps the internal DOM tree back into a <strong>string</strong>. If the $filename is set, result string will save to file. </td>
</tr>
<tr>
<td>
<div class="returns">void</div>
load_file (<span class="var"> string $filename</span> )</td>
<td class="description"> Load contents from a from a file or a URL.</td>
</tr>
<tr>
<td>
<div class="returns">void</div>
set_callback ( <span class="var">string $function_name </span>)</td>
<td class="description">Set a callback function. </td>
</tr>
<tr>
<td>
<div class="returns">mixed</div>
find (<span class="var"> string $selector [, int $index] </span>)</td>
<td class="description">Find elements by the CSS selector. Returns the Nth element <strong>object</strong> if <strong>index</strong> is set, otherwise return an <strong>array</strong> of object. </td>
</tr>
</table>
<br>
<strong>Element</strong> methods & properties <br>
<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<th width="320">Name</th>
<th>Description</th>
</tr>
<tr>
<td>
<div class="returns">string</div>
<span class="var">[attribute]</span></td>
<td class="description">Read or write element's attribure value. </td>
</tr>
<tr>
<td>
<div class="returns">string</div>
tag</td>
<td class="description">Read or write the tag name of element.</td>
</tr>
<tr>
<td>
<div class="returns">string</div>
outertext</td>
<td class="description">Read or write the outer HTML text of element.</td>
</tr>
<tr>
<td>
<div class="returns">string</div>
innertext</td>
<td class="description">Read or write the inner HTML text of element.</td>
</tr>
<tr>
<td>
<div class="returns">string</div>
plaintext</td>
<td class="description">Read or write the plain text of element.</td>
</tr>
<tr>
<td>
<div class="returns">mixed</div>
find (<span class="var"> string $selector [, int $index] </span>)</td>
<td class="description">Find children by the CSS selector. Returns the Nth element <strong>object</strong> if <strong>index</strong> is set, otherwise, return an <strong>array</strong> of object. </td>
</tr>
</table>
<strong><br>
DOM</strong> traversing<br>
<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<th width="320">Name</th>
<th>Description</th>
</tr>
<tr>
<td>
<div class="returns">mixed</div>
$e->children ( <span class="var">[int $index]</span> ) </td>
<td class="description">Returns the Nth child <strong>object</strong> if <strong>index</strong> is set, otherwise return an <strong>array</strong> of children. </td>
</tr>
<tr>
<td>
<div class="returns">element</div>
$e->parent () </td>
<td class="description">Returns the parent of element. </td>
</tr>
<tr>
<td>
<div class="returns">element</div>
$e->first_child () </td>
<td class="description">Returns the first child of element, or <strong>null</strong> if not found. </td>
</tr>
<tr>
<td>
<div class="returns">element</div>
$e->last_child () </td>
<td class="description">Returns the last child of element, or <strong>null</strong> if not found. </td>
</tr>
<tr>
<td>
<div class="returns">element</div>
$e->next_sibling () </td>
<td class="description">Returns the next sibling of element, or<strong> null</strong> if not found. </td>
</tr>
<tr>
<td>
<div class="returns">element</div>
$e->prev_sibling () </td>
<td class="description">Returns the previous sibling of element, or <strong>null</strong> if not found. </td>
</tr>
</table>
</div>
<a name="camel"></a>
<h2>Camel naming convertions</h2>
<a class="top" href="#top">Top</a>
<div class="code">You can also call methods with W3C STANDARD camel naming convertions.<br>
<br>
<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<th width="50%">Method</th>
<th>Mapping</th>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">array</div>
$e->getAllAttributes () </td>
<td>
<div class="returns">array</div>
$e-><span class="var">attr</span></td>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">string</div>
$e->getAttribute ( <span class="var">$name</span> ) </td>
<td>
<div class="returns">string</div>
$e-><span class="var">attribute</span></td>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">void</div>
$e->setAttribute ( <span class="var">$name, $value</span> ) </td>
<td>
<div class="returns">void</div>
$value = $e-><span class="var">attribute</span></td>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">bool</div>
$e->hasAttribute ( <span class="var">$name</span> ) </td>
<td>
<div class="returns">bool</div>
isset($e-><span class="var">attribute</span>)</td>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">void</div>
$e->removeAttribute ( <span class="var">$name</span> ) </td>
<td>
<div class="returns">void</div>
$e-><span class="var">attribute</span> = null</td>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">element</div>
$e->getElementById ( <span class="var">$id</span> ) </td>
<td>
<div class="returns">mixed</div>
$e->find (<span class="var"> "#$id", 0 </span>)</td>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">mixed</div>
$e->getElementsById ( <span class="var">$id [,$index] </span> ) </td>
<td>
<div class="returns">mixed</div>
$e->find (<span class="var"> "#$id" [, int $index] </span>)</td>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">element</div>
$e->getElementByTagName (<span class="var">$name</span> ) </td>
<td>
<div class="returns">mixed</div>
$e->find (<span class="var"> $name, 0 </span>)</td>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">mixed</div>
$e->getElementsByTagName ( <span class="var">$name [, $index]</span> ) </td>
<td>
<div class="returns">mixed</div>
$e->find (<span class="var"> $name [, int $index] </span>)</td>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">element</div>
$e->parentNode () </td>
<td>
<div class="returns">element</div>
$e->parent () </td>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">mixed</div>
$e->childNodes ( <span class="var">[$index]</span> ) </td>
<td>
<div class="returns">mixed</div>
$e->children ( <span class="var">[int $index]</span> ) </td>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">element</div>
$e->firstChild () </td>
<td>
<div class="returns">element</div>
$e->first_child () </td>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">element</div>
$e->lastChild () </td>
<td>
<div class="returns">element</div>
$e->last_child () </td>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">element</div>
$e->nextSibling () </td>
<td>
<div class="returns">element</div>
$e->next_sibling () </td>
</tr>
<tr bgcolor="#EEEEEE">
<td>
<div class="returns">element</div>
$e->previousSibling () </td>
<td>
<div class="returns">element</div>
$e->prev_sibling () </td>
</tr>
</table>
</div>
<div><br>
Author: S.C. Chen (me578022@gmail.com)<br>
Original idea is from Jose Solorzano's <a href="http://php-html.sourceforge.net/">HTML Parser for PHP 4</a>. <br>
Contributions by: Contributions by: Yousuke Kumakura, Vadim Voituk, Antcs<br>
</div>
</div>
</body>
</html>
<!--$Rev: 165 $-->