PHP get page title function
PHP's get_meta_tags function can extract meta-description, meta-keywords etc but cannot find title of the page. Therefore I use following function to catch title of a remote url or a local xhtml file.
function get_page_title($url){
if( !($data = file_get_contents($url)) ) return false;
if( preg_match("#<title>(.+)<\/title>#iU", $data, $t)) {
return trim($t[1]);
} else {
return false;
}
}
Similar entries
- Between operator in PHP
- Simple Hello World Module for Drupal 6
- A HTML-Example Page
- How to use custom function aliases in PHP
- Get top 100 words / keywords from a text with PHP
- How to hide / encrypt CCK Email field with JS against spammer
- Photo Album / Picture Gallery Script with PHP
- How to change 'Welcome to the Frontpage', index-title of Joomla 1.5
- Free Banners : 468 x 60
- Social bookmarking Client for multiple update
- CSS Text effects for MSIE
- Mouseover images with CSS
- Web 2.0 Style two Side Background, Dark to Light Effect
- How to override php mail function to catch abuse / spammer
- Sleep Function for JavaScript like PHP
- Search in text files recursively with PHP - Grep
- need help for customizing PHP-grep files search
- abcdefghijklmnopqrstuvwxyz
- PHP Block for Custom Role under Drupal 6
- php

Comments
Change your user agent / browser / client PHP
Change your user agent / browser / client to avoid being blocked from remote server:
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11');Using U (ungreedy) is a good
Using U (ungreedy) is a good idea because you could get multiple title parts from a page.
Very helpful method..
Hello,
Awesome method. I just wanted to get title and you solved my problem.. Thank you very much
Thanks
Thanks, I am looking for this option, u save my day.
Post new comment