Home Tutorial Php Examples Printing the title of a remote page

 
 

Printing the title of a remote page
Posted on: July 30, 2009 at 12:00 AM
Advertisement
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);
?>
 

Advertisement

Related Tags for Printing the title of a remote page:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 30, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com