Jump to content

Retrieve blog header image

Recommended Posts

I'm trying to create a visual stream of activity for my website and desktop application, incorporating gallery images, videobox videos, and blog entries into a single stream sorted by date. I have it all working except the blog entry header images. This is important, because the blog header image is what I plan to show in the background of the tiles for blog entries, making the whole system cohesive. I'd prefer not to post any screenshots of my application here, but it looks good and it's a really nice visual way to just take in all recent activity at a glance.

Edited by Interferon
Link to comment
Share on other sites

This code does it, but does not properly parse the CSS attribute, so if any other style elements are added it will fail:


function getBlogHeaderImage($url)
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $page = curl_exec($ch);

    // Remove some HTML elements
    $dom = new DOMDocument();

    $finder = new DomXPath($dom);
    $items = $finder->query("//*[contains(@class, '$classname')]");
    if ($items->length == 0) return "";

    $style = $items[0]->getAttribute("style");

    $style = str_replace('background-image: url("', '', $style);
    $style = str_replace('")', '', $style);

    return $style;

$url = 'https://linustechtips.com/blogs/entry/2114-you-dont-want-to-use-a-linux-converted-chromebook/';




Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...