Usando domDocument e analisando informações, eu gostaria de obter o conteúdo 'href' de uma tag 'a' [duplicado]
Possible Duplicate:
Expressão regular para pegar o atributo href de um elemento A
Isso exibe o que há entre osa
, mas gostaria de obter uma maneira de obter ohref
conteúdo também.
Existe uma maneira de fazer isso usando o domDocumen
$html = file_get_contents($uri);
$html = utf8_decode($html);
/*** a new dom object ***/
$dom = new domDocument;
/*** load the html into the object ***/
@$dom->loadHTML($html);
/*** discard white space ***/
$dom->preserveWhiteSpace = false;
/*** the table by its tag name ***/
$tables = $dom->getElementsByTagName('table');
/*** get all rows from the table ***/
$rows = $tables->item(0)->getElementsByTagName('tr');
/*** loop over the table rows ***/
foreach ($rows as $row)
{
$a = $row->getElementsByTagName('a');
/*** echo the values ***/
echo $a->item(0)->nodeValue.'<br />';
echo '<hr />';
}