Jump to content

Using PHP To Get A Site title and meta description from a url


Brandon_R

Recommended Posts

you can use file_get_contents("http://yoursite.com");

 

here is the title function

function getMetaTitle($content){
$pattern = "|<[\s]*title[\s]*>([^<]+)<[\s]*/[\s]*title[\s]*>|Ui";
if(preg_match($pattern, $content, $match))
return $match[1];
else
return false;
}

 

and its easy to get meta tags use this:

$blah=get_meta_tags("http://yoursite.com");

 

hope this helps.

Link to comment
Share on other sites

<?php
function getMetaDescription($content) {
    $metaDescription = false;
    $metaDescriptionPatterns = array("/]*>/Ui", "/]*>/Ui");
    foreach ($metaDescriptionPatterns as $pattern) {
        if (preg_match($pattern, $content, $match))
             $metaDescription = $match[1];
             break;
    }
    return $metaDescription;
}
?>

Link to comment
Share on other sites

<?php
$tags = get_meta_tags('http://www.example.com/');

echo $tags['author'];       // name
echo $tags['keywords'];     // php documentation
echo $tags['description'];  // a php manual
echo $tags['geo_position']; // 49.33;-86.59
?>

 

this was collected from php.net hope this helps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.