PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?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
$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...
}