and

Php how get meta tags name from url page

Solution: get_meta_tags Does fetch only meta data without additional html tags or info Here is a code that fetches all meta and information about any webpage use the way you want for your code: You should get your meta @ in fallowing code or you can use it the way you would want to Question: i’m creating a kind of facebook link sharing that gets all meta tags with a parcitular class called MetaData code is very simple: Now, it returns each meta tag I get meta tags like this : then : I have the description, but without : How can i get this ?

Php how get meta tags name from url page

$test = get_meta_tags('http://viedemerde.fr'); 

I have the description, but without :

get_meta_tags Does fetch only meta data without additional html tags or info

Here is a code that fetches all meta and information about any webpage use the way you want for your code:

You should get your meta @ $test[«metaTags»][«description»][«html»];

in fallowing code or you can use it the way you would want to

function getUrlData($url) < $result = false; $contents = getUrlContents($url); if (isset($contents) && is_string($contents)) < $title = null; $metaTags = null; preg_match('/([^>]*)/si', $contents, $match); if (isset($match) && is_array($match) && count($match) > 0) < $title = strip_tags($match[1]); >preg_match_all('/"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $contents, $match); if (isset($match) && is_array($match) && count($match) == 3) < $originals = $match[0]; $names = $match[1]; $values = $match[2]; if (count($originals) == count($names) && count($names) == count($values)) < $metaTags = array(); for ($i = 0, $limiti = count($names); $i < $limiti; $i++) < $metaTags[$names[$i]] = array( 'html' =>htmlentities($originals[$i]), 'value' => $values[$i] ); > > > $result = array( 'title' => $title, 'metaTags' => $metaTags ); > return $result;> function getUrlContents($url, $maximumRedirections = null, $currentRedirection = 0) < $result = false; $contents = @file_get_contents($url); // Check if we need to go somewhere else if (isset($contents) && is_string($contents)) < preg_match_all('/"]*)"?' . '[\s]*[\/]?[\s]*>/si', $contents, $match); if (isset($match) && is_array($match) && count($match) == 2 && count($match[1]) == 1) < if (!isset($maximumRedirections) || $currentRedirection < $maximumRedirections) < return getUrlContents($match[1][0], $maximumRedirections, ++$currentRedirection); >$result = false; > else < $result = $contents; >> return $contents;> $test = getUrlData('http://ocsidtechnologies.com'); //Replace with your URL here echo '
';print_r($test); 

PHP - get_meta_tags() Function, Syntax. array get_meta_tags ( string $filename [, bool $use_include_path = false ] ) get_meta_tags () function can open filename and parse it line by line for tags in a file. The parsing stops at . get_meta_tags () function can return an array with all parsed meta tags. The value of the name property becomes key, the …

Get meta tags with MetaData class in php

i'm creating a kind of facebook link sharing that gets all meta tags with a parcitular class called MetaData

require_once('metadata.class.php'); $metaData = MetaData::fetch('http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.html'); // returns an associative array var_dump($metaData->tags()); foreach ($metaData as $key => $value) < echo "$key =>$value"; > 

Now, it returns each meta tag but if i would select a specific tag how i could do it ?

For example, i want get only title, description and og image.

I tried with $value['description'] but it returns empty call, any ideas ?

array(26) < ["title"]=>string(60) "Ken Robinson: How schools kill creativity | Video on TED.com" ["description"]=> string(149) "Sir Ken Robinson makes an entertaining and profoundly moving case for creating an education system that nurtures (rather than undermines) creativity." ["keywords"]=> string(63) "TED,Talks,children,creativity,culture,dance,education,parenting" ["medium"]=> string(5) "video" ["apple-itunes-app"]=> string(101) "app-id=376183339,app-argument=http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.html" ["robots"]=> string(13) "index, follow" ["og:title"]=> string(60) "Ken Robinson: How schools kill creativity | Video on TED.com" ["og:description"]=> string(149) "Sir Ken Robinson makes an entertaining and profoundly moving case for creating an education system that nurtures (rather than undermines) creativity." ["og:image"]=> string(48) "http://images.ted.com/images/ted/221_389x292.jpg" ["og:url"]=> string(71) "http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.html" ["og:type"]=> string(11) "video.other" ["video:tag"]=> array(8) < [0]=>string(3) "TED" [1]=> string(5) "Talks" [2]=> string(8) "children" [3]=> string(10) "creativity" [4]=> string(7) "culture" [5]=> string(5) "dance" [6]=> string(9) "education" [7]=> string(9) "parenting" > ["video:duration"]=> string(4) "1164" ["video:release_date"]=> string(10) "1151367060" ["twitter:card"]=> string(7) "summary" ["twitter:site"]=> string(9) "@tedtalks" ["twitter:title"]=> string(60) "Ken Robinson: How schools kill creativity | Video on TED.com" ["twitter:description"]=> string(149) "Sir Ken Robinson makes an entertaining and profoundly moving case for creating an education system that nurtures (rather than undermines) creativity." ["twitter:image:src"]=> string(48) "http://images.ted.com/images/ted/221_389x292.jpg" ["twitter:app:name:iphone"]=> string(9) "TED Talks" ["twitter:app:id:iphone"]=> string(9) "376183339" ["twitter:app:url:iphone"]=> string(71) "http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.html" ["twitter:app:name:ipad"]=> string(9) "TED Talks" ["twitter:app:id:ipad"]=> string(9) "376183339" ["twitter:app:url:ipad"]=> string(71) "http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.html" ["fb:app_id"]=> string(15) "201021956610141" > title => Ken Robinson: How schools kill creativity | Video on TED.comdescription => Sir Ken Robinson makes an entertaining and profoundly moving case for creating an education system that nurtures (rather than undermines) creativity.keywords => TED,Talks,children,creativity,culture,dance,education,parentingmedium => videoapple-itunes-app => app-id=376183339,app-argument=http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.htmlrobots => index, followog:title => Ken Robinson: How schools kill creativity | Video on TED.comog:description => Sir Ken Robinson makes an entertaining and profoundly moving case for creating an education system that nurtures (rather than undermines) creativity.og:image => http://images.ted.com/images/ted/221_389x292.jpgog:url => http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.htmlog:type => video.othervideo:tag => Arrayvideo:duration => 1164video:release_date => 1151367060twitter:card => summarytwitter:site => @tedtalkstwitter:title => Ken Robinson: How schools kill creativity | Video on TED.comtwitter:description => Sir Ken Robinson makes an entertaining and profoundly moving case for creating an education system that nurtures (rather than undermines) creativity.twitter:image:src => http://images.ted.com/images/ted/221_389x292.jpgtwitter:app:name:iphone => TED Talkstwitter:app:id:iphone => 376183339twitter:app:url:iphone => http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.htmltwitter:app:name:ipad => TED Talkstwitter:app:id:ipad => 376183339twitter:app:url:ipad => http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.htmlfb:app_id => 201021956610141f 

Источник

How to extract title and meta description using PHP Simple HTML DOM Parser?

How can I extract a page's title and meta description using the PHP Simple HTML DOM Parser? I just need the title of the page and the keywords in plain text.

9 Answers 9

$html = new simple_html_dom(); $html->load_file('some_url'); //To get Meta Title $meta_title = $html->find("meta[name='title']", 0)->content; //To get Meta Description $meta_description = $html->find("meta[name='description']", 0)->content; //To get Meta Keywords $meta_keywords = $html->find("meta[name='keywords']", 0)->content; 

NOTE: The names of meta tags are casesensitive!

I just took a look at the HTML DOM Parser, try:

$html = new simple_html_dom(); $html->load_file('xxx'); //put url or filename in place of xxx $title = $html->find('title'); echo $title->plaintext; $descr = $html->find('meta[description]'); echo $descr->plaintext; 

This code does not work for me (anymore? --- the answer is older than the latest version of the library), because find may return more than one element. To get it working I need to add a second parameter with a value of 0 to find: $html->find('title', 0)->plaintext;

$html = new simple_html_dom(); $html->load_file('http://www.google.com'); $title = $html->find('title',0)->innertext; 

$html->find('title') will return an array

so you should use $html->find('title',0) , so does meta[description]

Taken from LeiXC's solution above, you need to use the simple html dom class:

$dom = new simple_html_dom(); $dom->load_file( 'websiteurl.com' );// put your own url in here for testing $html = str_get_html($dom); $descr = $html->find("meta[name=description]", 0); $description = $descr->content; echo $description; 

I have tested this code and yes it is case sensitive (some meta tags use a capital D for description)

Here is some error checking for spelling errors:

if( is_object( $html->find("meta[name=description]", 0)) )< echo $html->find("meta[name=description]", 0)->content; > elseif( is_object( $html->find("meta[name=Description]", 0)) )< echo $html->find("meta[name=Description]", 0)->content; > 

Источник

How to Get Title and Metadata (meta tags) from URL using PHP

In this article, I am going to show you how to get webpage Titles and Meta tags from external website URLs using PHP. Scroll down to the page so you can see the full source code available for this.

Mostly, All external websites are used to specify the 3 common metadata for the web page are page title, page description, and page keywords. These all meta tags information fetched using PHP. The page description and page keywords within tag and page title is tag.

 
codeat21
loadHTML($data); // Parse DOM to get Title data $nodes = $dom->getElementsByTagName('title'); $title = $nodes->item(0)->nodeValue; // Parse DOM to get meta data $metas = $dom->getElementsByTagName('meta'); $description = ''; $keywords = ''; $site_name = ''; $image = ''; for($i=0; $ilength; $i++)< $meta = $metas->item($i); if($meta->getAttribute('name') == 'description')< $description = $meta->getAttribute('content'); > if($meta->getAttribute('name') == 'keywords')< $keywords = $meta->getAttribute('content'); > if($meta->getAttribute('property') == 'og:site_name')< $site_name = $meta->getAttribute('content'); > if($meta->getAttribute('property') == 'og:image')< $image = $meta->getAttribute('content'); > > echo "Title: $title". '

'; echo "Description: $description". '

'; echo "Keywords: $keywords". '

'; echo "site_name: $site_name". '

'; echo "image: $image"; ?>

Output

  • Title: Home - codeat21.com - Web Designing and Development Tutorials Website.
  • Description: codeat21.com is a web designing and development tutorials website. Learn Web Development, HTML, CSS, PHP, MySQL, JavaScript, Node JS, React JS, jQuery, etc..
  • Keywords:
  • site_name: codeat21.com - Web Designing and Development Tutorials Website.
  • image:
  • Get meta tags from URL
  • Get meta tags from url javascript
  • Get_meta_tags
  • how to add meta tags in php website
  • How to add meta tags dynamically in PHP
  • Php get title from url
  • How to add meta title and description in php
  • php get page title from url, curl get meta tags
  • get og meta tags javascript
  • dynamically change og meta tags

Recent Posts

Источник

Читайте также:  Косинус угла в java
Оцените статью