Skip to main content

Fetch Facebook OG Meta Tags with PHP

OG (Open Graph) meta tag is designed by Facebook to make url share easy on social networking websites. Now days these tags are widely used by other websites. If you are running a social networking website or planning to run one. You can make url sharing easy by fetching these tags.

Today I will show you how we can get/fetch OG meta tags with PHP script.


fetch_og PHP function

/**
 * Fetch OG Metatags
 * @param string $url
 * 
 * @return array
 */
function fetch_og($url)
{
    $data = file_get_contents($url);
    $dom = new DomDocument;
    @$dom->loadHTML($data);
     
    $xpath = new DOMXPath($dom);
    # query metatags with og prefix
    $metas = $xpath->query('//*/meta[starts-with(@property, \'og:\')]');

    $og = array();

    foreach($metas as $meta){
        # get property name without og: prefix
        $property = str_replace('og:', '', $meta->getAttribute('property'));
        # get content
        $content = $meta->getAttribute('content');
        $og[$property] = $content;
    }

    return $og;
}

Usages

$og = fetch_og('http://www.w3bees.com');
echo $og['title'];

Comments

  1. Replies


    1. Hai ma thú cấp tám bên trong đều là ma thú cấp tám sơ kỳ.

      Hắc Ám Thần Điện lần này xuất ra tổng cộng là bảy con ma thú hắc ám, bây giờ chỉ còn lại ba con, nhưng ba con chỉ là ma thú cấp tám sơ kỳ.

      Cự Viên Tộc ma thú đối với ma thú của Hắc Ám Thần Điện phát khởi công kích, Nhạc Thuần và Nhạc Sử Chân cũng đều chọn một hán tử áo đen mà tấn công.

      Loại thực lực đối kháng này hoàn toàn kém xa, Nhạc Sử Chân và Nhạc Thuần hai người cũng chỉ có tu vi thất tinh Đấu Tôn, cộng them với đấu kỹ cao thâm của Nhạc gia, khiến cho hán tử áo đen bị trọng thương.

      Kỳ thật bốn hán tử áo đen này lúc đầu đã muốn chạy trốn nhưng không thể nào thoát ra hkoir.

      Bọn họ khôdongtam
      mu moi ra hom nay
      tim phong tro
      http://nhatroso.com/
      nhạc sàn
      tổng đài tư vấn luật
      văn phòng luật hà nội
      tổng đài tư vấn luật
      thành lập công ty trọn gói
      http://we-cooking.com/
      chém gió
      trung tâm tiếng anhng có cơ hội trốn mà thôi, nếu như thật sự chạy thoát thì cũng bị nhốt trong cấm chế của Nhạc Thành.

      Lúc này, Tiểu Song ở phía xa xa không làm gì, hai người tự động lùi ra ngoài, miễn cho mọi người bị vưỡng chân vướng tay.

      Hỏa diễm công kích của Địa Ma Lão Nhân không lâu đã trở nên tán loạn, nửa năm

      Delete
  2. For some URLs I never get the correct response.

    Can anyone please help me on this issue.

    ReplyDelete
  3. for any post from nytimes.com I always get null while fetching og.

    Please help !

    ReplyDelete
  4. This blog is really informative. I gained more knowledge by reading your post. Thanks for providing us the useful information with us. Your blog is really helpful for me in attaining my knowledge in a right way.

    CCNA Training in Chennai

    ReplyDelete
  5. Thank you for having taken your time to provide us with your valuable information relating to your stay with us.we are sincerely concerned.., Most importantly, you Keepit the major...
    SEO Training in Chennai

    ReplyDelete
  6. Great Article I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because it becomes more and more interesting from the starting lines until the end. So Thank you for sharing a COOL Meaningful stuff with us Keep it up..!

    SAP training in Chennai

    ReplyDelete
  7. what if there are multiple og:images??

    Its gets me the last one. I want to get the first og:image instead

    ReplyDelete
  8. Thanks for this wonderful post. The information in this article is very helpful to me. Thanks a lot for sharing. Keep blogging.
    Best Truth or Dare Questions for Kids

    ReplyDelete
  9. Thanks for this wonderful post. The information in this article is very helpful to me. Thanks a lot for sharing. Keep blogging.
    Interest Waypoint

    ReplyDelete
  10. You truly did more than visitors’ expectations. Thank you for rendering these helpful, trusted, edifying and also cool thoughts on the topic.
    ME/M.Tech Project Center in Chennai | ME/M.Tech Project Center in Velachery

    ReplyDelete
  11. Thanks for sharing. I see the novelty of your writing, I will share it for everyone to read together. I look forward to reading many articles from you geometry dash

    ReplyDelete
  12. Needed to compose one little word yet thanks for the suggestions that you are contributed here...
    Best Online Software Training Institute | RPA Training

    ReplyDelete
  13. Very useful article. I have understood many applications of hot mail
    hotmail.com sign in

    ReplyDelete
  14. cara menggugurkan hamil kandungan dengan cepat dan akurat terbukti ampuh untuk melunturkan janin kehamilan muda 1 minggu hingga 1 , 2 , 3 dan 4 bulan
    obat penggugur kandungan adalah suatu bentuk proses berakhirnya kehamilan dengan dikeluarkannya janin ( fetus ) atau embrio sebelum memiliki kemampuan untuk berkembang dan bertahan hidup diluar rahim , sehingga bisa menyebabkan kematiannya pada janin
    Disini akan kami beritahukan kepada Anda langkah cara cepat menggugurkan kandungan dengan cepat dan selamat adalah KURET dan obat aborsi
    Kunyit memang tidak di baik di konsumsi oleh ibu hamil yang sedang hamil muda sehubungan dengan sifatnya untuk melancarkan haid , dan di percayai sebagai obat telat datang bulan
    jual obat aborsi paling manjur Misiprostol Cytotec asli terbukti ampuh melunturkan janin kuat tanpa kuret dengan bersih untuk usia 1 , 2 , 3 sampai 4 bulan dengan aman

    ReplyDelete
  15. Thanks for the command of this topic, thanks to that I got here. Cool thing.

    Tamara

    ReplyDelete
  16. Really great work. Your article was very helpful.Thanks for sharing valuable points.Keep sharing.Thank You
    rpa training in chennai | rpa training in velachery | trending technologies list 2018

    ReplyDelete
  17. Thanks for such a nice article on Blueprism.Amazing information of Blueprism you have . Keep sharing and updating this wonderful blog on Blueprism
    Thanks and regards,
    blue prism training in chennai
    blue prism training institute in chennai
    Blueprism certification in chennai

    ReplyDelete
  18. Supreet Solutions is the Best RPA Online Training Institute in Hyderabad which offers RPA Online Training by 15+ years of industry experts. From our training, you can acquire working knowledge skills on various Robotics Tools like Automation Anywhere, Blue Prism, UI Path. We Provide Best RPA Online Training With Live Practicals.
    Best, Live RPA Online Training In USA,Hyderabad | Online RPA Training In USA, Hyderabad
    Click Here Best RPA Online Training to go to RPA Online Training Institute Details.

    ReplyDelete
  19. Best RPA Online Training Institute In Hyderabad, RPA Online Training Institute In Hyderabad, Best RPA Online Training In Hyderabad, RPA Course In Hyderabad, RPA Training, RPA Training In Hyderabad, RPA Online Training In Hyderabad, Blue Prism Training In Hyderabad, Automation Training In Hyderabad, Blue Prism Online Training In Hyderabad, Automation Online Training In Hyderabad, Automation Course In Hyderabad, Automation Online Course In Hyderabad, Automation Training Institutes In Hyderabad, Automation Online Training Institutes In Hyderabad, RPA Course, Automation Course, Automation Training, RPA Course Fee In Hyderabad, RPA Training In Hyderabad Ameerpet, Best RPA Training Institutes In Hyderabad, RPA Training In Ameerpet, RPA Online Training Institutes In Hyderabad.
    Best, Live RPA Online Training In USA,Hyderabad | Online RPA Training In USA, Hyderabad
    Click Here Best RPA Online Training to go to RPA Online Training Institute Details.

    ReplyDelete
  20. Needed to compose one little word yet thanks for the suggestions that you are contributed here...

    Python Training in Chennai

    ReplyDelete
  21. Fiz uma next to have access to, you can access your email, you can review the email using the system, then click here to confirm the last 4 to do it In the last part of you in the last part of it 83 brain da certo oque eu faço.
    delete hotmail account

    ReplyDelete
  22. RPA Training in hyderabad is offered by Digital Nest, Which Specialises in training RPA courses on RPA tools Like Blue Prism Training, ui path training, Automation anywhere .

    RPA training is offered by real time industry experts in hyderabad by Experts from Tech Mahindra, Infosys, Delioitte. who has 10+ years of experience in dealing with various Tools and techniques specially in automations.

    RPA training in hyderabad is in demand as many students and working professionals from various background are looking forward to the best courses that can help them in switching their jobs and also help the freshers grabbing jobs

    ReplyDelete
    Replies
    1. https://www.digitalnest.in/rpa-training-in-hyderabad/

      Delete

  23. Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.

    Advanced AWS Online Training | Advanced Online AWS Certification Course - Gangboard
    Best AWS Training in Chennai | Amazon Web Services Training Institute in Chennai Velachery, Tambaram, OMR
    Advanced AWS Training in Bangalore |Best AWS Training Institute in Bangalore BTMLA ,Marathahalli

    ReplyDelete
  24. Thank you for sharing such great information with us. I really appreciate everything that you’ve done here and am glad to know that you really care about the world that we live in
    python training Course in chennai
    python training in Bangalore
    Python training institute in bangalore

    ReplyDelete
  25. Fantastic work! This is the type of information that should follow collective approximately the web. Embarrassment captivating position Google for not positioning this transmit higher! Enlarge taking place greater than and visit my web situate

    Java training in Pune

    Java interview questions and answers

    Java training in Chennai | Java training institute in Chennai | Java course in Chennai

    Java training in Bangalore | Java training institute in Bangalore | Java course in Bangalore

    ReplyDelete
  26. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    best rpa training in chennai
    rpa training in chennai
    rpa interview questions and answers
    automation anywhere interview questions and answers
    blueprism interview questions and answers
    uipath interview questions and answers
    rpa training in bangalore

    ReplyDelete
  27. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    Best Devops online Training
    Online DevOps Certification Course - Gangboard

    ReplyDelete
  28. very nice blog rpa training in hyderabad

    ReplyDelete
  29. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.
    aws training in bangalore
    RPA Training in bangalore
    Python Training in bangalore
    Selenium Training in bangalore
    Hadoop Training in bangalore

    ReplyDelete

Post a Comment

Popular posts from this blog

Multiple File Upload with PHP

Sometimes we need to allow our users to upload multiple file upload. On my previous post I was shown the basic of simple file upload with PHP. Today I am going to show you how to allow users to upload multiple files. It is almost similar like simple file upload but we need to do some modification with html markup and php code. multiple attribute is needed to add on the html markup. Major web browsers like Firefox, Chrome, Safari and IE 9+ support this attribute. Now I am going to show you how to upload multiple file with PHP and basic HTML form.

Live Comment System with jQuery Ajax PHP and MySQL

Recently I have been made a post that focused on how to submit form without page refreshing. That post shows the basic functionality of using jQuery Ajax. On the same follow this post will describe how we can create a comment system to post an instant comment without page refreshing. Let's start...

Resize Image While Uploading with PHP

On my previous post I was shown an example how to upload file with php and html. It was based on php simple image upload functionality. Today I am going to show you little bit advance of image uploading. Suppose if you run a website and want to allow users to upload image files than you need to think little bit about server's space and bandwidth. For this purpose you need to do some optimization with image files. Image resize while uploading is one of them. All major website do it in the same way. If a user uploads a 5mb image file they resize it in different sizes and store on there server. It helps them to seed up there website and reduce there budget. Now take a look, how we can do it ourself.