Share on Google+Share on Google+

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. 

$file = fopen ("C:\\wamp\\www\\projects\\public_html\upload\\upload.php\\", "r");
if (!$file) {
echo "<p>Unable to open remote file.\n";
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];


Posted on: July 30, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.