Printing the title of a remote page


 

Printing the title of a remote page

In this example you will learn about printing the title of a remote page.

In this example you will learn about printing the title of a remote page.

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);
?>
 

Ads