• support@answerspoint.com

How to find Page Title and meta content of HTML , using PHP

642

I want to try figure out how to get the

<title>my Page title</title>
<meta name="keywords" content="Keywords developer" />
<meta name="description" content="This is the description of page" />

1Answer


0
<?php
//if
$url="http://www.answerspoint.com/questions/403/how-to-find-page-title-and-meta-content-of-html-using-php";

//for Meta tag (keyword, description)
$tags = get_meta_tags($url);
$meta_keywords=$tags['keywords']; 
$meta_description=$tags['description']; 


//for Page Title


$page_title=pageTitle($url);
function pageTitle($page_url)
{
	 $read_page=file_get_contents($page_url);
	 preg_match("/<title.*?>[\n\r\s]*(.*)[\n\r\s]*<\/title>/", $read_page, $page_title);
	  if (isset($page_title[1]))
	  {
			if ($page_title[1] == '')
			{
				  return $page_url;
			}
			$page_title = $page_title[1];
			return trim($page_title);
	  }
	  else
	  {
			return $page_url;
	  }
}


?>

 

  • answered 1 year ago
  • Sunny Solu

Your Answer

    Facebook Share