Printing the title of the remote page
In the following example we have extracted the title of the page accessed from a remote web server.
For this, first define the file name to be printed the title.
Open the file.
If file would not open, it will print "unable to open file"
and if it becomes successful to open, it will print the title of the page.
<?php
$file = fopen ("C:\\wamp\\www\\projects\\public_html\upload\\upload.php\\", "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 (preg_match ("@\<title\>(.*)\</title\>@i", $line, $out)) {
$title = $out[1];
break;
}
}
fclose($file);
?>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.