Jump to content

Parse opengraph image tag problem


Semnomic

Recommended Posts


<form action="form.php" method="get">
<label>Redbubble Design url:
<input style height="20" width="40" type="numeric" name="url" size="35" />
</label>
<p></p>
<label>Design Short Desc:
<input style height="20" width="40" type="numeric" name="desc" size="35"/>
</label>
<p></p>
<label>Product Hashtags:
<input style height="20" width="40" type="numeric" name="tags" size="35"/>
</label>
<p></p>
<input type="submit">
</form>
<p></p>
<?php
parse_str($_SERVER['QUERY_STRING']);
echo $url;?>



<?php
$page_content = file_get_contents('$url');
$dom_obj = new DOMDocument();
$dom_obj->loadHTML($page_content);
$meta_val = null;

foreach($dom_obj->getElementsByTagName('meta') as $meta) {

if($meta->getAttribute('property')=='og:image'){ 

    $meta_val = $meta->getAttribute('content');
}
}
echo $meta_val;

?>

First time posting here so i hope i got it right.

 

im making a small program that parses OG image from a url.

 

The above code works if I replace $url in the main php section of code with the actual url > https://www.redbubble.com/people/podartist/works/22431751-neon-orange-puffy-stitch-quilt

 

Can anyone see what im doing wrong when i try and use the stored string $url ? $url is exactly the same as the url so im lost. :(

 

Hope that makes sense. Thanks in advance

 

 

Link to comment
Share on other sites

Why do you have quotes around $url in your file_get_contents call? Any quotes are unnecessary here, and single quotes prevent string interpolation, meaning you're passing the literal string "$url" as your parameter.

Link to comment
Share on other sites

I know thats where the problem is i tried      ''   and   ""  so i dont know why its not working,

 

I can echo it so i know its there/stored but i can use it in the second part of code. What im trying to do is get that OG image to appear on my form.

 

How would you make a small form that grabs an OG image from that url i gave and echos it out after you submit? If i can get it to echo i will be ok with the image part.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.