How to transform the output of this function into a array
? In future I would like to call only the result of a particular row, such as $palavraschave[1]
.
<?php
$url= 'https://www.telelistas.net/ac/acrelandia';
function palavras_chave($pc){
$doc= new DOMDocument();
$doc->loadHTML(file_get_contents($pc));
$finder = new DomXPath($doc);
$tableid="Content_dataListPalavrasChave";
$nodes = $finder->query("//*[contains(concat(' ', normalize-space(@id), ' '), ' $tableid ')]");
foreach ($nodes as $node){
$links= $node->getElementsByTagName("a");
foreach ($links as $link){
//echo $link->getAttribute("href")."<br>";
$linktratado = $link->getAttribute("href")."<br>";
parse_url($linktratado, PHP_URL_PATH);
$keys = explode("/", $linktratado);
echo $keys[5];
}
}
}
palavras_chave("$url");
?>