@ 2018-05-17T17:55:49Z <?php
$html = <<<HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="description" content="a descrição do seu site em no máximo 90 caracteres">
<meta name="keywords" content="escreva palavras-chaves curtas, máximo 150 caracteres">
<title>Título do Documento</title>
</head>
<body>
<!-- Aqui fica a página que será visível para todos, onde pode-se inserir
textos, imagens, links para outras páginas, etc, geralmente usa-se: -->
<div>Tag para criar-se uma 'caixa', um bloco, mais utilizada com "Cascading Style Sheets
(Folhas de Estilo em Cascata)</div>
<span>Tag para modificação de uma parte do texto da página</span>
<img src="endereço_de_uma_imagem.jpg" />
<a href="http://www.wikipedia.org">Wikipedia, A Enciclopédia Livre</a>
<a href="http://www.exemplo.org/pasta/subpasta/">Pasta e subpasta</a>
</body>
HTML;
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXpath($doc);
$elements = $xpath->query("//a[contains(@href,'pasta/subpasta')]");
foreach($elements as $domNode)
{
var_dump($domNode);
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.4.1 - 8.4.3 object(DOMElement)#3 (27) {
["tagName"]=>
string(1) "a"
["className"]=>
string(0) ""
["id"]=>
string(0) ""
["schemaTypeInfo"]=>
NULL
["firstElementChild"]=>
NULL
["lastElementChild"]=>
NULL
["childElementCount"]=>
int(0)
["previousElementSibling"]=>
string(22) "(object value omitted)"
["nextElementSibling"]=>
NULL
["nodeName"]=>
string(1) "a"
["nodeValue"]=>
string(16) "Pasta e subpasta"
["nodeType"]=>
int(1)
["parentNode"]=>
string(22) "(object value omitted)"
["parentElement"]=>
string(22) "(object value omitted)"
["childNodes"]=>
string(22) "(object value omitted)"
["firstChild"]=>
string(22) "(object value omitted)"
["lastChild"]=>
string(22) "(object value omitted)"
["previousSibling"]=>
string(22) "(object value omitted)"
["nextSibling"]=>
string(22) "(object value omitted)"
["attributes"]=>
string(22) "(object value omitted)"
["isConnected"]=>
bool(true)
["ownerDocument"]=>
string(22) "(object value omitted)"
["namespaceURI"]=>
NULL
["prefix"]=>
string(0) ""
["localName"]=>
string(1) "a"
["baseURI"]=>
NULL
["textContent"]=>
string(16) "Pasta e subpasta"
}
Output for 8.3.0 - 8.3.16 object(DOMElement)#3 (27) {
["schemaTypeInfo"]=>
NULL
["tagName"]=>
string(1) "a"
["className"]=>
string(0) ""
["id"]=>
string(0) ""
["firstElementChild"]=>
NULL
["lastElementChild"]=>
NULL
["childElementCount"]=>
int(0)
["previousElementSibling"]=>
string(22) "(object value omitted)"
["nextElementSibling"]=>
NULL
["nodeName"]=>
string(1) "a"
["nodeValue"]=>
string(16) "Pasta e subpasta"
["nodeType"]=>
int(1)
["parentNode"]=>
string(22) "(object value omitted)"
["parentElement"]=>
string(22) "(object value omitted)"
["childNodes"]=>
string(22) "(object value omitted)"
["firstChild"]=>
string(22) "(object value omitted)"
["lastChild"]=>
string(22) "(object value omitted)"
["previousSibling"]=>
string(22) "(object value omitted)"
["nextSibling"]=>
string(22) "(object value omitted)"
["attributes"]=>
string(22) "(object value omitted)"
["isConnected"]=>
bool(true)
["ownerDocument"]=>
string(22) "(object value omitted)"
["namespaceURI"]=>
NULL
["prefix"]=>
string(0) ""
["localName"]=>
string(1) "a"
["baseURI"]=>
NULL
["textContent"]=>
string(16) "Pasta e subpasta"
}
Output for 8.1.0 - 8.1.31 , 8.2.0 - 8.2.27 object(DOMElement)#3 (23) {
["schemaTypeInfo"]=>
NULL
["tagName"]=>
string(1) "a"
["firstElementChild"]=>
NULL
["lastElementChild"]=>
NULL
["childElementCount"]=>
int(0)
["previousElementSibling"]=>
string(22) "(object value omitted)"
["nextElementSibling"]=>
NULL
["nodeName"]=>
string(1) "a"
["nodeValue"]=>
string(16) "Pasta e subpasta"
["nodeType"]=>
int(1)
["parentNode"]=>
string(22) "(object value omitted)"
["childNodes"]=>
string(22) "(object value omitted)"
["firstChild"]=>
string(22) "(object value omitted)"
["lastChild"]=>
string(22) "(object value omitted)"
["previousSibling"]=>
string(22) "(object value omitted)"
["nextSibling"]=>
string(22) "(object value omitted)"
["attributes"]=>
string(22) "(object value omitted)"
["ownerDocument"]=>
string(22) "(object value omitted)"
["namespaceURI"]=>
NULL
["prefix"]=>
string(0) ""
["localName"]=>
string(1) "a"
["baseURI"]=>
NULL
["textContent"]=>
string(16) "Pasta e subpasta"
}
Output for 8.0.0 - 8.0.30 object(DOMElement)#3 (23) {
["tagName"]=>
string(1) "a"
["schemaTypeInfo"]=>
NULL
["firstElementChild"]=>
NULL
["lastElementChild"]=>
NULL
["childElementCount"]=>
int(0)
["previousElementSibling"]=>
string(22) "(object value omitted)"
["nextElementSibling"]=>
NULL
["nodeName"]=>
string(1) "a"
["nodeValue"]=>
string(16) "Pasta e subpasta"
["nodeType"]=>
int(1)
["parentNode"]=>
string(22) "(object value omitted)"
["childNodes"]=>
string(22) "(object value omitted)"
["firstChild"]=>
string(22) "(object value omitted)"
["lastChild"]=>
string(22) "(object value omitted)"
["previousSibling"]=>
string(22) "(object value omitted)"
["nextSibling"]=>
string(22) "(object value omitted)"
["attributes"]=>
string(22) "(object value omitted)"
["ownerDocument"]=>
string(22) "(object value omitted)"
["namespaceURI"]=>
NULL
["prefix"]=>
string(0) ""
["localName"]=>
string(1) "a"
["baseURI"]=>
NULL
["textContent"]=>
string(16) "Pasta e subpasta"
}
Output for 7.1.0 - 7.1.20 , 7.2.0 - 7.2.33 , 7.3.16 - 7.3.33 , 7.4.0 - 7.4.33 object(DOMElement)#3 (18) {
["tagName"]=>
string(1) "a"
["schemaTypeInfo"]=>
NULL
["nodeName"]=>
string(1) "a"
["nodeValue"]=>
string(16) "Pasta e subpasta"
["nodeType"]=>
int(1)
["parentNode"]=>
string(22) "(object value omitted)"
["childNodes"]=>
string(22) "(object value omitted)"
["firstChild"]=>
string(22) "(object value omitted)"
["lastChild"]=>
string(22) "(object value omitted)"
["previousSibling"]=>
string(22) "(object value omitted)"
["nextSibling"]=>
string(22) "(object value omitted)"
["attributes"]=>
string(22) "(object value omitted)"
["ownerDocument"]=>
string(22) "(object value omitted)"
["namespaceURI"]=>
NULL
["prefix"]=>
string(0) ""
["localName"]=>
string(1) "a"
["baseURI"]=>
NULL
["textContent"]=>
string(16) "Pasta e subpasta"
}
preferences:dark mode live preview
103.21 ms | 419 KiB | 5 Q