Page 1 of 1
Parse info from remote location
Posted: Sun Jan 16, 2005 2:10 pm
by Cronikeys
Code: Select all
<?php
$file = fopen ("http://www.example.com/", "r");
if (!$file) {
echo "<p>Unable to open remote file.\n";
exit;
}
while (!feof ($file)) {
$line = fgets ($file, 1024);
/* This only works if the title and its tags are on one line */
if (eregi ("<title>(.*)</title>", $line, $out)) {
$title = $outї1];
break;
}
}
fclose($file);
?>
This code is from php.net, and it works great, however what if I need to get something within tags that are NOT on the same line

Posted: Sun Jan 16, 2005 3:33 pm
by JAM
Perhaps....
Code: Select all
$file = fopen ("http://phpdn.jam.nu/Tagfinding/test.html", "r"); // exists, check its source to see what it looks like...
if (!$file) {
echo "<p>Unable to open remote file.\n";
exit;
}
$buffer = '';
while (!feof ($file)) {
$buffer .= fgets ($file, 1024);
}
fclose($file);
if (eregi ("<sometag>(.*)</sometag>", $buffer, $out)) {
echo $title = $outї1]; // remove echo to just set the variable with the result...
}
Posted: Sun Jan 16, 2005 7:30 pm
by feyd
There's also file_get_contents() instead of the fopen()/fread()/fclose() routine, and using preg_match() or preg_match_all() instead of ereg*..
as another avenue..