Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8468107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:50:26+00:00 2026-06-10T15:50:26+00:00

I am looking at page source and basically want to get the og:image image

  • 0

I am looking at page source and basically want to get the “og:image” image url

I am using the following, which works, and I think (apart from relative URLs issue) covers all eventualities – but it might not be the most efficient way to do it – I have commented the code to show what each line is doing ($html is the source code):

$og_img = explode( '<meta property="og:image" content=', $html); // strip out beginning
$og_img = explode('>', $og_img[1]); // strip out end
if(substr($og_img[0], -1)=='/'){ $og_img[0] = substr($og_img[0], 0, -1); } // strip / if used /> to close the tag
$og_img[0] = str_replace("'", "", $og_img[0]); // strip ' ... ' apostrophes if used
$og_img[0] = str_replace('"', '', $og_img[0]); // strip " ... " doubke quotes if used

Is there a more efficient way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:50:28+00:00Added an answer on June 10, 2026 at 3:50 pm

    Don’t roll it yourself.

    Go use DOM. E.g.

    $doc = new DOMDocument();
    @$doc->loadHTML($html);
    $metas = $doc->getElementsByTagName('meta');
    for ($i = 0; $i < $metas->length; $i++)
    {
        $meta = $metas->item($i);
        if($meta->getAttribute('property') == 'og:image')
            $og_image_content = $meta->getAttribute('content');
    }
    

    or (haven’t tried it though) use:

    get_meta_tags()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When looking to get data from a web page whats the recommended method if
I am looking for a way to, give a URL, get the source of
I was looking a source code of a particular page of my project and
I'm basically looping over a bunch of youtube video url's to get each video's
I am looking for a tool (open source) that will crawl all my page
I was looking at the page source for an ASP.NET page I wrote and
The Report Viewer control apparently only works in a Web Forms page (I'm using
I was looking at Chrome's page source for its beautiful saved password management in
Please see #7755661 first. I am using ECL and basically want to execute some
Looking at the Single page application beta in the MVC 4 I don't see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.