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

  • Home
  • SEARCH
  • 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 4002336
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:00:53+00:00 2026-05-20T08:00:53+00:00

I am looking to draw html of a webpage inside my website. Take this

  • 0

I am looking to draw html of a webpage inside my website.

Take this scenario:

I have a website that checks availability of a hotel. But instead of hosting that hotel’s images on my server. I simple curl, a specific page on the hotels website that contains their images.

Can I grab anything from the html and display it on my website? using their HTML code, but only the div(s) or images that i want to display?

I’m using this code, sourced from:

http://davidwalsh.name/download-urls-content-php-curl

As practice and arguments sake, lets try and display Google’s logo from their homepage.

function get_data($url)
{
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

$returned_content = get_data('http://www.google.com');
echo '<base href="http://www.google.com/" />';
echo $returned_content;

Thanks to @alex I have started to play with DOMDocument in PHP’s lib. However, I have hit a snag.

    function get_data($url)
{
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

$url = "www.abc.net.au";
$html = get_data($url);

$dom = new DOMDocument;
@$dom->loadHTML($html);
$logo = $dom->getElementById("abcLogo");
var_dump($logo);

Returns: object(DOMElement)[2]

How do I parse this further? Or Simply just print/echo the contents of the DIV with that id..?

  • 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-05-20T08:00:53+00:00Added an answer on May 20, 2026 at 8:00 am

    Once you have found a DOM element, it can be a bit tricky to get the HTML of the element itself (rather than just its contents).

    You can get the XML value of a single element very easily with DOMDocument::saveXML:

    echo $dom->saveXML($logo);
    

    This may be good enough for you. I believe there is a change coming that will add this functionality to saveHTML as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've searched on this, but nothing has what I'm looking for. http://www.mail-archive.com/pygtk@daa.com.au/msg10529.html -- Nobody
Im looking for a way to draw the OUTLINE of a circle that will
Looking to do a bit of refactoring... Using NHibernate I have this query currently
i'm looking for a way to draw multiple images (downloaded from a webservice) inside
I have seen this question/answer: How do you draw text on a <canvas> tag
I'm writing an application that is looking to draw basic polygons and ellipses on
I've been looking into draw and draw.x11 packages that come with Go. I didn't
I'm looking for a way to draw a grid (i.e. http://www.artlex.com/ArtLex/g/images/grid.gif ) inside of
On a HTML canvas I have multiple points starting from 1 to N, this
I'm looking for a quality tool to draw PetriNets with that has an interface

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.