@@ 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. |
@@ 417-440 (lines=24) @@ | ||
414 | * |
|
415 | * @return SimpleHtmlDomNode|SimpleHtmlDomNode[]|SimpleHtmlDomNodeBlank |
|
416 | */ |
|
417 | public function getElementsByTagName($name, $idx = null) |
|
418 | { |
|
419 | $nodesList = $this->document->getElementsByTagName($name); |
|
420 | ||
421 | $elements = new SimpleHtmlDomNode(); |
|
422 | ||
423 | foreach ($nodesList as $node) { |
|
424 | $elements[] = new SimpleHtmlDom($node); |
|
425 | } |
|
426 | ||
427 | if (null === $idx) { |
|
428 | return $elements; |
|
429 | } else { |
|
430 | if ($idx < 0) { |
|
431 | $idx = count($elements) + $idx; |
|
432 | } |
|
433 | } |
|
434 | ||
435 | if (isset($elements[$idx])) { |
|
436 | return $elements[$idx]; |
|
437 | } else { |
|
438 | return new SimpleHtmlDomNodeBlank(); |
|
439 | } |
|
440 | } |
|
441 | ||
442 | /** |
|
443 | * Find list of nodes with a CSS selector. |