@@ 318-341 (lines=24) @@ | ||
315 | * |
|
316 | * @return SimpleHtmlDomNode|SimpleHtmlDomNode[]|SimpleHtmlDomNodeBlank |
|
317 | */ |
|
318 | public function getElementsByTagName($name, $idx = null) |
|
319 | { |
|
320 | $nodesList = $this->node->getElementsByTagName($name); |
|
321 | ||
322 | $elements = new SimpleHtmlDomNode(); |
|
323 | ||
324 | foreach ($nodesList as $node) { |
|
325 | $elements[] = new self($node); |
|
326 | } |
|
327 | ||
328 | if (null === $idx) { |
|
329 | return $elements; |
|
330 | } else { |
|
331 | if ($idx < 0) { |
|
332 | $idx = count($elements) + $idx; |
|
333 | } |
|
334 | } |
|
335 | ||
336 | if (isset($elements[$idx])) { |
|
337 | return $elements[$idx]; |
|
338 | } else { |
|
339 | return new SimpleHtmlDomNodeBlank(); |
|
340 | } |
|
341 | } |
|
342 | ||
343 | /** |
|
344 | * Create a new "HtmlDomParser"-object from the current context. |
@@ 440-463 (lines=24) @@ | ||
437 | * |
|
438 | * @return SimpleHtmlDomNode|SimpleHtmlDomNode[]|SimpleHtmlDomNodeBlank |
|
439 | */ |
|
440 | public function getElementsByTagName($name, $idx = null) |
|
441 | { |
|
442 | $nodesList = $this->document->getElementsByTagName($name); |
|
443 | ||
444 | $elements = new SimpleHtmlDomNode(); |
|
445 | ||
446 | foreach ($nodesList as $node) { |
|
447 | $elements[] = new SimpleHtmlDom($node); |
|
448 | } |
|
449 | ||
450 | if (null === $idx) { |
|
451 | return $elements; |
|
452 | } else { |
|
453 | if ($idx < 0) { |
|
454 | $idx = count($elements) + $idx; |
|
455 | } |
|
456 | } |
|
457 | ||
458 | if (isset($elements[$idx])) { |
|
459 | return $elements[$idx]; |
|
460 | } else { |
|
461 | return new SimpleHtmlDomNodeBlank(); |
|
462 | } |
|
463 | } |
|
464 | ||
465 | /** |
|
466 | * Find list of nodes with a CSS selector. |