<?php
header('Content-Type: text/html; charset=utf-8');
$url = '
http://leparisien.fr/';
$html = file_get_contents($url);
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXpath($doc);
$nodes = $xpath->query('//a');
?>
<html>
<head>
<style>td{border:1px solid black;padding:5px;}th{background:darkgrey;}.red{color:red;}</style>
</head>
<body>
<?php
if($nodes)
{
echo '<h1>les <span class="red">'.$nodes->length. '</span> liens de la page : '.$url.'</h1>';
echo '<table>
<thead><tr><th>ancre</th><th>title</th><th>url</th><th>rel</th></tr></thead><tbody>';
foreach($nodes as $node) {
if($node->getAttribute('rel')){$rel = $node->getAttribute('rel');}else{$rel= "-";}
if($node->getAttribute('title')){$title = $node->getAttribute('title');}else{$title= "-";}
if($node->nodeValue){$ancre = $node->nodeValue;}else{$rel= "-";}
if($node->getAttribute('href')){$href = $node->getAttribute('href');}else{$rel= "-";}
echo '<tr><td>'. $ancre .'</td><td>'. $title .'</td><td>'. $href .'</td><td>'.$rel.'</td></tr>';
}
echo '</tbody></table>';
}
else
{
echo 'aucun lien trouvé';
}
?>
</body>
</html>