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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:49:42+00:00 2026-06-12T17:49:42+00:00

I am trying to get the contents from span, class, div from external other

  • 0

I am trying to get the contents from span, class, div from external other domain to mine personal website. The source code of the website http://www.example.com is

    <div id="h_gold" class="h_metal">
      <div class="hm_inside">
        <div class="hm_title">Gold</div>
        <span class="arr_price_down">- 13.42 <img src="images/downarrow.jpg" alt="down" /></span>
        <div class="clear"></div>
        <div class="hm_cad">USD</div>
        <div class="hm_bottom">
          <div> Bid<br />
            <span>$1,749.20</span> </div>
          <div class="ask"> Ask<br />
            <span>$1,750.20</span> </div>
        </div>
        <!-- .hm_bottom-->
      </div>
      <!-- hm_inside-->
    </div>
    <!-- h_metal-->
    <div id="h_silver" class="h_metal">
      <div class="hm_inside">
        <div class="hm_title">Silver</div>
        <span class="arr_price_down">- 0.54 <img src="images/downarrow.jpg" alt="down" /></span>
        <div class="clear"></div>
        <div class="hm_cad">USD</div>
        <div class="hm_bottom">
          <div> Bid<br />
            <span>$33.40</span> </div>
          <div class="ask"> Ask<br />
            <span>$33.50</span> </div>
        </div>
        <!-- .hm_bottom-->
      </div>
      <!-- hm_inside-->
    </div>
    <!-- h_metal-->

I have a problem here.. i tried the following code.. but it doesnt loop, I only get the contents from the first < div class=”hm_bottom” > , rests are not in the output,

    <?php
    function get_string_between($string, $start, $end)
    {
        $string = " ".$string;
        $ini = strpos($string,$start);
        if ($ini == 0)
            return "";
        $ini += strlen($start);
        $len = strpos($string,$end,$ini) - $ini;
        return substr($string,$ini,$len);
    }
    $data = file_get_contents("http://www.example.com/ajax.php?metal_cur=USD");

    $pricediv = get_string_between($data, '<div class="hm_bottom">', '</span>');
    $pricetext = strip_tags($pricediv);
    echo $pricetext;
    ?>

Secondly, i searched stachoverflow again, i found one solved, but doesnt perfectly matches my needs. the output is kinda okay, but i just want numerical data from the output to be placed in the particular div id i define.

    <?php 
    $page = file_get_contents('http://www.example.com/ajax.php?metal_cur=USD');
    $doc = new DOMDocument();
    $doc->loadHTML($page);
    $divs = $doc->getElementsByTagName('div');
    foreach($divs as $div) {
        // Loop through the DIVs looking for one withan id of "content"
        // Then echo out its contents (pardon the pun)
        if ($div->getAttribute('class') === 'hm_bottom') {
             echo $div->nodeValue;
        }
    }
    ?>

the above code is from second search from stackoverflow

  • 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-12T17:49:43+00:00Added an answer on June 12, 2026 at 5:49 pm

    You can use str_get_html or file_get_html as the case may be

    $html = str_get_html($html);
    $amounts = array();
    foreach ( $html->find("div[class=hm_bottom] span") as $span ) {
        $amount = trim($span->plaintext);
        if (strpos($amount, "\$") === 0)
            $amounts[] = $amount;
    }
    
    var_dump($amounts);
    

    Output

    array
      0 => string '$1,749.20' (length=9)
      1 => string '$1,750.20' (length=9)
      2 => string '$33.40' (length=6)
      3 => string '$33.50' (length=6)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<div id = 'eventcontainer' > <span id = 'class'> <?php //Getting posts from DB
I am trying to retrieve some information from other website to my website(Legally)... I
I'm trying to get content from an RSS2 feed from one of my sites
I'm trying to get the content from all the nodes in the bookmarks menu
I'm trying to get the contents of a HttpServletRequest. Here is how I'm doing
I'm trying to get file contents, replace some parts of it using regular expressions
I'm trying to get the contents of a directory using shell script. My script
I'm trying to get the contents of a directory using shell script. My script
I'm trying to get the contents of a cell in a row in a
I am trying to get the contents of tags into variables in my java

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.