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 8705413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:21:10+00:00 2026-06-13T03:21:10+00:00

I’m trying edit a plugin which I use to add meta open graph tags

  • 0

I’m trying edit a plugin which I use to add meta open graph tags to the header. The problem with it is that it would only let me choose one picture for the whole site.. this is what I’ve done:

preg_match_all('/<img .*?(?=src)src=\"([^\"]+)\"/si', $hdog_base, $image);

if (strlen($hdog_base) <= 25) 
{
    if (substr($image[0], 0, 4) != 'http') 
    {
        $image[0] = JURI::base().$image[0]; 
    }
    $hdog_image_tmp = $image[0];
}
else
{
    if (substr($image[1], 0, 4) != 'http') 
    {
        $image[1] = JURI::base().$image[1]; 
    }
    $hdog_image_tmp = $image[1];
}
$hdog_image =   '<meta property="og:image" content="'.$hdog_image_tmp.'" />
';

$hdog_base is the current webpage I’m on.
The first if-statement would show the very first picture, which is the logo (used for ex. homepage), and the else would show the second picture (which would be different on each page), but the result only comes out like this, no matter if I’m on the homepage or anywhere else on the site:

<meta property="og:image" content="http://mysite.com/Array" />

Any suggestions?

Thanks in advance,

Update:
The biggest fault I’m making is that I am trying to find the images in a url, not the actual webpage. But just the link. So how would I go on to get the contents of the current page in a string? Instead of $hdog_base, which is nothing but a link.

UPDATE, SOLVED:

I used

$buffer = JResponse::getBody();

to get the webpage in HTML

and then DOM for the rest

$doc = new DOMDocument();
@$doc->loadHTML($buffer);

$images = $doc->getElementsByTagName('img');
if (strlen($hdog_base) <= 26) 
{
    $image = $images->item(0)->getAttribute('src');
} 
else 
{
    $image = $images->item(1)->getAttribute('src');
}
if (substr($image, 0, 4) != 'http') $image = JURI::base().$image;
$hdog_image =   '<meta property="og:image" content="'.$image.'" />
';

Thanks a lot cpilko for your help! 🙂

  • 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-13T03:21:11+00:00Added an answer on June 13, 2026 at 3:21 am

    Using preg_match_all with more than one subpattern in the regular expression will return a multidimensional array. In your code $image[n] is an array. If you cast an array as a string in php, as you are doing it returns the text Array.

    EDIT: Using a regex to parse HTML isn’t ideal. You are better off doing it with DOMDocument:

    $doc = new DOMDocument();
    @$doc->loadHTML($hdog_base);
    
    $images = $doc->getElementsByTagName('img');
    if (strlen($hdog_base) <= 25) {
        $image = $images->item(0)->getAttribute('src');
    } else {
        $image = $images->item(1)->getAttribute('src');
    }
    if (substr($image[0], 0, 4) != 'http') $image .= JURI::base();
    $hdog_image =   '<meta property="og:image" content="'.$hdog_image_tmp.'" />
    ';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.