diff --git "a/Retos/Reto #18 - WEB SCRAPING [Dif\303\255cil]/php/almonteagudor.php" "b/Retos/Reto #18 - WEB SCRAPING [Dif\303\255cil]/php/almonteagudor.php" new file mode 100644 index 0000000000..1f4779d798 --- /dev/null +++ "b/Retos/Reto #18 - WEB SCRAPING [Dif\303\255cil]/php/almonteagudor.php" @@ -0,0 +1,35 @@ +loadHTMLFile($url); + +$elements = $document->getElementsByTagName("h1"); + +$element = searchElementByString($elements, $text); + +if($element) { + echo $element->textContent . "\n"; + + while($element->nextElementSibling?->tagName === 'blockquote') { + $element = $element->nextElementSibling; + + echo $element->textContent . "\n"; + } +} else { + echo "No se ha encontrado: $text\n"; +} + +function searchElementByString(DOMNodeList $list, string $text): ?DOMElement +{ + foreach ($list as $element) { + if(str_contains($element->textContent, $text)) { + return $element; + } + } + + return null; +}