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
    • 579
    Comment on it

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

    1. <html>
    2. <head>
    3. </head>
    4. <body>
    5. <?php
    6. function getTitle($Url){
    7. $str = file&#95;get&#95;contents($Url);
    8. if(strlen($str)>0){
    9. preg&#95;match("/\<title\>(.*)\<\/title\>/",$str,$title);
    10. return $title[1];
    11. }
    12. }
    13. //Example:
    14. echo 'TITLE :'.getTitle("http://www.cnn.com");
    15.  
    16.  
    17. // Assuming the above tags are at www.cnn.com
    18. $tags = get&#95;meta&#95;tags('http://www.whoznext.com/')
    19. or die("Could not fetch meta tags");
    20.  
    21. // Notice how the keys are all lowercase now, and
    22. // how . was replaced by _ in the key.
    23. echo 'AUTHOR '.$tags['author'].'<br/>'; // name
    24. echo 'KEYWORDS '.$tags['keywords'].'<br/>'; // php documentation
    25. echo 'Description '.$tags['description'].'<br/>'; // a php manual
    26. echo 'Location '.$tags['geo&#95;position'].'<br/>'; // 49.33;-86.59
    27.  
    28. ?>
    29. Test!
    30. </body>
    31. </html>

    OUTPUT:

    1. TITLE :CNN.com International - Breaking, World, Business, Sports, Entertainment and Video News
    2.  
    3. AUTHOR:
    4. 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

    1. 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.
    2.  
    3. Location

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: