[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

retrieve the contents of <title></title> of a remote web site

from a php script what is the best and most efficient way to retrieve the contents of <title></title> of a remote web site
0
ee-gd
Asked:
ee-gd
  • 2
1 Solution
 
Ray PaseurCommented:
Read the site with either CURL or file_get_contents() and use explode() or a regular expression to extract the title from the page.

What URL would you like to extract the title from?  I'll show you a little example script to do it.
0
 
Ray PaseurCommented:
This site does not need CURL to get to it.  Hope this helps, ~Ray
<?php // RAY_extract_title.php
error_reporting(E_ALL);

$url = 'http://www.LandonBaseball.com/';
$htm = file_get_contents($url);
$rgx
= '#'           // REGEX DELIMITER
. '(<title>)'   // GROUP CONSISTING OF THE TITLE TAG
. '(.*?)'       // GROUP CONSISTING OF ANYTHING -- WE WANT TO KEEP THIS SECOND GROUP
. '(</title>)'  // GROUP CONSISTINT OF THE END-TITLE TAG
. '#'           // REGEX DELIMITER
. 'i'           // CASE-INSENSITIVE
;
preg_match_all($rgx, $htm, $mat);
echo htmlentities($mat[2][0]);

Open in new window

0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now