Domuta Marcel
Domuta Marcel

Reputation: 509

Substitute a phrase and characters from a result with simple html dom

My code working good to result me an external part of the price of the item from an online store, but is loaded with standard html, css and letters, I wanna be just numbers without "," or "ABC" just numbers like "123".

This is a part of external mobile-store site:

<div class="prod-box-separation" style="padding-left:15px;padding-right:15px;text-align:center;padding-top:7px;">
   <div style="color:#cc1515;">
      <div class="price-box">
         <span class="regular-price" id="product-price-47488">
            <span >
               <span class="price">2.443,<sup>00</sup> RON</span>                                                    
            </span>
         </span>
      </div>
   </div>
</div>
<div class="prod-box-separation" style="padding-left:10px;padding-right:10px;">
   <style>
      .delivery {
     display:block;
      }
  </style>
  <p class="availability in-stock">
     <div class="stock_info">Produs in  stoc</div>
     <div class="delivery"><div class="delivery_title">Livrare(in timpul orelor de   program):</div>
     <div class="delivery_item">Bucuresti - BANEASA : imediat</div>
     <div  class="delivery_item">Bucuresti - EROILOR : luni dupa ora 13.00.</div>
     <div  class="delivery_item">CURIER : Marti</div>
  </div>
  </p>

Garanţie: 12 luni

Here is my actual code:

<?php
include_once('../simple_html_dom.php');
$dom = file_get_html("http://www.site.com/page.html");
// alternatively use str_get_html($html) if you have the html string already...
foreach ($dom->find('span[class=price]') as $node)
{
echo $node->innertext;
} 
?>   

and my result is this: 2.443,<sup>00</sup> RON But correct result will be: 2.443 or 2443

Upvotes: 0

Views: 79

Answers (1)

James Scholes
James Scholes

Reputation: 7906

You could do something like this:

<?php
include_once('../simple_html_dom.php');
$dom = file_get_html("http://www.site.com/page.html");
// alternatively use str_get_html($html) if you have the html string already...
foreach ($dom->find('span[class=price]') as $node)
{
$result = $node->innertext;
$price = explode(",<sup>", $result);
echo $price[0];
} 
?>   

Upvotes: 2

Related Questions