0

我的代码运行良好,可以使我从在线商店获得商品价格的外部部分,但加载了标准的 html、css 和字母,我只想成为没有“,”或“ABC”的数字,只是像“123”这样的数字”。

这是外部移动商店网站的一部分:

<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 卢尼

这是我的实际代码:

<?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;
} 
?>   

我的结果是这样的:2.443,<sup>00</sup> RON但正确的结果将是:2.4432443

4

1 回答 1

2

你可以这样做:

<?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];
} 
?>   
于 2013-01-27T21:57:20.740 回答