Get Meta Tags in PHP

Discussion in 'PHP' started by faisalmnr, Jun 23, 2008.

  1. #1
    Hi everyone, Someone help me to getting the Title of page using the PHP, i already getting all the meta tags using get_meta_tags function in php, but this function cannot rerieve the Title of the page, and i also want the title of the page with meta tage. Please help me in this matter.
    Thanks in advance.
     
    faisalmnr, Jun 23, 2008 IP
  2. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
     function url_title($url) {
    		$cont = @file_get_contents($url);
    	
    		$a = explode("<title>", $cont);
    		$b = explode("</title>", $a[1]);
    	
    		if (!$b[0]){
    	
    			$a = explode("<TITLE>", $cont);
    			$b = explode("</TITLE>", $a[1]);
    	
    		}
    		return $b[0];
    	}
    PHP:
    ignore the preg_match remark :)
     
    juust, Jun 23, 2008 IP
  3. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Use preg, it's better for this.

    preg_match('/<title>([^>]*)<\/title>/si', $contents, $match );
     
    Danltn, Jun 23, 2008 IP
  4. dannet

    dannet Well-Known Member

    Messages:
    864
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    153
    #4
    EDIT: Sorry, delete me :)
     
    dannet, Jun 24, 2008 IP