Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Get the title and meta tags from a url in php

    • 0
    • 1
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 452
    Comment on it

    To get the title and meta tags from a website you can use the following code :

    <html>
    <head>
    </head>
    <body>
    <?php
    function getTitle($Url){
            $str = file&#95;get&#95;contents($Url);
            if(strlen($str)>0){
                    preg&#95;match("/\<title\>(.*)\<\/title\>/",$str,$title);
                    return $title[1];
            }
    }
    //Example:
    echo 'TITLE :'.getTitle("http://www.cnn.com");
    
    
    // Assuming the above tags are at www.cnn.com
    $tags = get&#95;meta&#95;tags('http://www.whoznext.com/')
     or die("Could not fetch meta tags");
    
    // Notice how the keys are all lowercase now, and
    // how . was replaced by _ in the key.
    echo 'AUTHOR '.$tags['author'].'<br/>';      // name
    echo 'KEYWORDS '.$tags['keywords'].'<br/>';    // php documentation
    echo 'Description '.$tags['description'].'<br/>';  // a php manual
    echo 'Location '.$tags['geo&#95;position'].'<br/>'; // 49.33;-86.59
    
    ?>
    Test!
    </body>
    </html>
    

    OUTPUT:

    TITLE :CNN.com International - Breaking, World, Business, Sports, Entertainment and Video News
    
    AUTHOR:
    KEYWORDS 
    

    CNN, CNN news, CNN International, CNN International news, CNN Edition, Edition news, news, news online, breaking news, U.S. news, world news, global news, weather, business, CNN Money, sports, politics, law, technology, entertainment, education, travel, health, special reports, autos, developing story, news video, CNN Intl, podcasts, world blogs

    Description CNN.com International delivers breaking news from across the globe and information on the latest top stories, business, sports and entertainment headlines. Follow the news as it happens through: special reports, videos, audio, photo galleries plus interactive maps and timelines.
    
    Location 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: