manout
manout

Reputation: 41

How can i get wall post same as facebook using php

maybe it not the correct question but i'm looking for help, i have use curl, DOMDocument, and file_get_contents to get a image tag as facebook do but i can't. enter image description here

some thing like this.

Upvotes: 0

Views: 178

Answers (2)

manout
manout

Reputation: 41

My code look like this: i'm trying to get image image from yahoo link just like test https://es.finance.yahoo.com/noticias/amazon-prev-vender-un-smartphone-200856947.html

header('Content-Type: application/json');
if(isset($_GET['c_txt'])){
$url = $_GET['c_txt'];
if(curl_init($url)){
    $html = file_get_contents($url);

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

    $tags = $doc->getElementsByTagName('img');

    foreach ($tags as $tag) {
           echo $tag->getAttribute('src') . "\n";
    }
  }
}

but the result looks like:

https://sb.scorecardresearch.com/b?  c1=2&c2=7241469&c7=es.finance.yahoo.com%2Fnoticias%2Famazon-prev-vender-un-smartphone-200856947.html&c5=1185584786&c15=$&cv=2.0&cj=1
https://s.yimg.com/dh/ap/default/130307/expansion_header_article.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/dh/ap/default/130711/masnoticiasen2.jpg
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png

and not the image that display at facebook, the tag what i want is this one: enter image description here

Upvotes: 0

Brad
Brad

Reputation: 163436

Facebook uses specific Open Graph meta tags that publishers can use to suggest an image, title, and description for Facebook to use when sharing a URL. You will want to load the HTML with DOMDocument, and then look for these tags.

Look for tags with og: in the name, like this:

<meta property="og:image" content="http://example.com/image.png" />

See also: http://davidwalsh.name/facebook-meta-tags

Upvotes: 1

Related Questions