/    Sign up×
Community /Pin to ProfileBookmark

extracting meta data

hi guys does php have any built in functions that would
allow me to extract meta description and meta keywords?

I’m building a link partner directory, and would like for this
info to be automatically extracted from the page that
is being submitted.

It would be displayed in a form that can be editted
before being submitted. Some pages already have a good
description and keywords in their meta data, so if it could
be extracted the submitter could save time by not typing
in a description and keywords.

if there are no built in functions, could it be done without
needing to use regular expressions?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 07.2008 — [code=php]
<?php
$keywords = $description = '';

$dom = new DomDocument();
$dom->loadHTMLFile('http://www.charles-reace.com/');
$metaList = $dom->getElementsByTagName('meta');
for($ix = 0, $total = $metaList->length; $ix < $total; $ix++)
{
$node = $metaList->item($ix);
if(strtolower($node->getAttribute('name')) == 'keywords')
{
$keywords = $node->getAttribute('content');
}
elseif(strtolower($node->getAttribute('name')) == 'description')
{
$description = $node->getAttribute('content');
}
}

echo "<p><strong>Keywords:</strong> $keywords</p>n";
echo "<p><strong>Description:</strong> $description</p>n";
?>
[/code]
Copy linkTweet thisAlerts:
@bsmbahamasauthorNov 07.2008 — thanks for the quick response, never seen it done using the DOM like this, but i did find a tutorial using php get_meta_data()

will try both. thanks.
×

Success!

Help @bsmbahamas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...