@@ 299-322 (lines=24) @@ | ||
296 | * |
|
297 | * @return SimpleHtmlDomNode|SimpleHtmlDomNode[]|SimpleHtmlDomNodeBlank |
|
298 | */ |
|
299 | public function getElementsByTagName($name, $idx = null) |
|
300 | { |
|
301 | $nodesList = $this->node->getElementsByTagName($name); |
|
302 | ||
303 | $elements = new SimpleHtmlDomNode(); |
|
304 | ||
305 | foreach ($nodesList as $node) { |
|
306 | $elements[] = new self($node); |
|
307 | } |
|
308 | ||
309 | if (null === $idx) { |
|
310 | return $elements; |
|
311 | } else { |
|
312 | if ($idx < 0) { |
|
313 | $idx = count($elements) + $idx; |
|
314 | } |
|
315 | } |
|
316 | ||
317 | if (isset($elements[$idx])) { |
|
318 | return $elements[$idx]; |
|
319 | } else { |
|
320 | return new SimpleHtmlDomNodeBlank(); |
|
321 | } |
|
322 | } |
|
323 | ||
324 | /** |
|
325 | * Create a new "HtmlDomParser"-object from the current context. |
@@ 381-404 (lines=24) @@ | ||
378 | * |
|
379 | * @return SimpleHtmlDomNode|SimpleHtmlDomNode[]|SimpleHtmlDomNodeBlank |
|
380 | */ |
|
381 | public function getElementsByTagName($name, $idx = null) |
|
382 | { |
|
383 | $nodesList = $this->document->getElementsByTagName($name); |
|
384 | ||
385 | $elements = new SimpleHtmlDomNode(); |
|
386 | ||
387 | foreach ($nodesList as $node) { |
|
388 | $elements[] = new SimpleHtmlDom($node); |
|
389 | } |
|
390 | ||
391 | if (null === $idx) { |
|
392 | return $elements; |
|
393 | } else { |
|
394 | if ($idx < 0) { |
|
395 | $idx = count($elements) + $idx; |
|
396 | } |
|
397 | } |
|
398 | ||
399 | if (isset($elements[$idx])) { |
|
400 | return $elements[$idx]; |
|
401 | } else { |
|
402 | return new SimpleHtmlDomNodeBlank(); |
|
403 | } |
|
404 | } |
|
405 | ||
406 | /** |
|
407 | * Find list of nodes with a CSS selector. |