this is wat i did..
<html>
<head></head>
<body>
<form>
<table>
<tr>
<td colspan="2"><img src="logo.jpg"></td>
</tr>
<tr>
<td>Name:</td>
<td><a href="http://www.yahoo.com">yahoo</a></td>
</tr>
<tr>
<td>Age:</td>
<td><a href="http://www.google.com">7yrs</a></td>
</tr>
<tr>
<td><a href="http://www.google.com">Location:</a></td>
<td><a href="http://www.google.com">google</a></td>
</tr>
<tr>
<td>Postal code:</td>
<td>123467</td>
</tr>
<tr>
<td>Phone:</td>
<td>987654321</td>
</tr>
</table>
</form>
</body>
</html>
$url="content.html";
$content = file($url);
$regex = @"(http:\/\/([\w.]+\/?)\S*)";
// count line
$numLines = count($content);
// process each line
for ($i = 0; $i < $numLines; $i++) {
$line = trim($content[$i]);
if (preg_match_all($regex,$line,$matches)) {
echo $line."<br/>";
print_r( $matches )."<br/>";
}
}
the result is
yahoo
Array ( [0] => Array ( [0] => http://www.yahoo.com">yahoo ) [1] => Array ( [0] => www.yahoo.com ) ) 7yrs
Array ( [0] => Array ( [0] => http://www.google.com">7yrs ) [1] => Array ( [0] => www.google.com ) ) Location:
Array ( [0] => Array ( [0] => http://www.google.com">Location: ) [1] => Array ( [0] => www.google.com ) ) google
Array ( [0] => Array ( [0] => http://www.google.com">google ) [1] => Array ( [0] => www.google.com ) )
yahoo, 7yrs, google or location are hyperlinks.. how do i extract the hyperlink or url to a variable??