用简单的html dom替换结果中的短语和字符

时间:2013-01-27 21:51:25

标签: php html dom

我的代码效果很好,可以让我从在线商店获得商品价格的外部部分,但是加载了标准的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 luni        

这是我的实际代码:

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

1 个答案:

答案 0 :(得分: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];
} 
?>