page title regex

Discussion in 'PHP' started by manilodisan, Jun 16, 2007.

  1. #1
    Anyone with a good regex to match the title of a page?
     
    manilodisan, Jun 16, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    function fetch_page_title($url)
    {
    	if (!$html = @file_get_contents($url))
    	{
    		trigger_error('Unable to open URL');
    		return false;
    	}
    	
    	return preg_match('/<title>([^<]+)<\/title>/i', $html, $title) ? trim($title[1]) : false;
    }
    
    
    PHP:
     
    nico_swd, Jun 16, 2007 IP
  3. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you nico. I should write you directly from now on :))
     
    manilodisan, Jun 16, 2007 IP