-2

Possible Duplicate:
How to extract img src, title and alt from html using php?

I want to replicate some functionality from Digg.com whereby when you post a new address it automatically scans the url and finds the page title.

Please tell how it is done in php......is there any other management system available by which you can make website like digg

Community
  • 1
  • 1
user1800923
  • 11
  • 1
  • 1
  • 3
  • 3
    Welcome to SE - your question as it stands shows no research. What have you tried so far? – Andrew Nov 05 '12 at 17:55
  • You'll want to get the title tag from the fetched page using `file_get_contents()`. See this: http://stackoverflow.com/questions/3711357/get-title-and-meta-tags-of-external-site – Jeremy Harris Nov 05 '12 at 17:56

3 Answers3

1

You can use file_get_contents() to get the data from the page, then use preg_match() along with a regex pattern to get the data between <title></title>

'/<title>(.*?)<\/title>'/
Prash
  • 1,915
  • 3
  • 20
  • 32
0

You can achieve this using Ajax call to the server, where you curl the URL and send back all the details you want. You might be interested in Title, Description, Keywords etc.

Pankaj
  • 5,132
  • 3
  • 28
  • 37
0
function get_title($url) {
  $ch = curl_init();
  $titleName = '';
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $data = curl_exec($ch);
  curl_close($ch);


  // data will contain the whole page you are looking for
  // You need to parse it for the string like this <title>Google</title>
  // start = strrpos($data, '<title>');
  // end = strrpos($data, '</title>');
  // substr($data, $start + 6, $end); 6 - length of title
  return $titleName;
}

You need to implement smarter way of parsing, because <title > Google < /title> it will no find.

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753