A database contains among other things the html code for pages. Some of the pages have hyperlinks. I want to print the various hyperlinks. I have tried this:
<?php
$host = 'localhost';
$usr = 'user name';
$pwd = 'password';
$db = 'dbs';
@mysql_connect($host,$usr,$pwd)
or die("<p>Kan ej ansluta till databasservern.</p>");
@mysql_select_db($db)
or die("<p>Kan ej ansluta till databasen " . $db . ".</p>");
$SQL = " SELECT * FROM jbs ";
$retid = mysql_query($SQL);
if (!$retid) { echo( mysql_error()); }
else {
$antal = mysql_num_rows($retid);
while ($row = mysql_fetch_array($retid)) {
$text = $row["text"];
$kategori = $row["kategori"];
$titel = $row["titel"];
$sida = $row["sida"];
$input = @file_get_contents($text) or die("Kunde inte läsa: $kategori - $titel");
$regexp = "/<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>/";
if(preg_match_all("$regexp/siU", $input, $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
if (!empty($regexp)) {
if (!empty($text)) {
for ($nr=0; $nr<$antal;)
echo "<tr><td>".$match[$nr][$nr+1]."</td></tr>";
$nr++;
}}}}}}
?>
It doesn't work. And I don't know where I go wrong. Is it at "$input = @file_get_contents($text)"?
Could your experts, please, help me out?