Skip to content

Instantly share code, notes, and snippets.

@hsleonis
Last active June 10, 2016 06:03
Show Gist options
  • Save hsleonis/314f463e823139aca261ef0d3fff4257 to your computer and use it in GitHub Desktop.
Save hsleonis/314f463e823139aca261ef0d3fff4257 to your computer and use it in GitHub Desktop.
get_meta_tags — Extracts all meta tag content attributes from a file and returns an array
<?php
/*
array get_meta_tags ( string $filename [, bool $use_include_path = false ] )
(PHP 4, PHP 5, PHP 7)
ref.: http://php.net/manual/en/function.get-meta-tags.php
*/
// Assuming the above tags are at www.example.com
$tags = get_meta_tags('http://www.example.com/');
// Notice how the keys are all lowercase now, and
// how . was replaced by _ in the key.
echo $tags['author']; // name
echo $tags['keywords']; // php documentation
echo $tags['description']; // a php manual
echo $tags['geo_position']; // 49.33;-86.59
// Only meta tags with name attributes will be parsed. Quotes are not required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment