无效标记上的简单html dom


simple html dom on non valid markup

我使用的是Simple HTML Dom,它在我的大部分数据上运行得很好。然而,on是一种痛苦,因为标记无效。在PHP中还有其他方法可以做到这一点吗。

我从一个页面上得到了这个结果,我正试图从中提取价格:

<taconite><replacecontent select="#basketcontents"><![CDATA[
                <table id="sellingb" cellpadding="10px" cellspacing="15" width="600" border="0">
                  <thead>
                    <tr class="title">
                      <th width="47" scope="col" align="center">Book</th>
                      <th width="213" scope="col" align="left">Title</th>
                      <th width="139" scope="col" align="left">ISBN/Barcode</th>
                      <th width="63" scope="col" align="left">Value</th>
                      <th width="29" scope="col">&nbsp;</th>
                    </tr>
                  </thead>
                  <tbody>
                              <tr class="trrow">
                                <td class="tdbook" align="center" valign="middle" ><img src="http://ecx.images-amazon.com/images/I/61JEp-wF3zL._SL75_.jpg" /><input name="offers_row_img[0]" type="hidden" value="http://ecx.images-amazon.com/images/I/61JEp-wF3zL._SL75_.jpg" /></td>
                                <td class="tdtitle">The Last Of Us (PS3) [Video Games]<input name="offers_row_title[0]" type="hidden" value="The Last Of Us (PS3) [Video Games]" /></td>
                                <td class="tdisbn">0711719274551<input name="offers_row_isbn[0]" type="hidden" value="0711719274551" /></td>
                                <td class="tdval">£15.00<input name="offers_row_price[0]" type="hidden" value="15.00" /></td>
                                <td class="tdremove"><input type="button" onclick="removeitem(0);" value="Reject Offer" /></td>
                              </tr>
                  </tbody>
                  </table>]]></replacecontent><eval><![CDATA[jQuery('#isbn').val('');]]></eval><replacecontent select="#price"><![CDATA[£15.00<br /><input type="button" class="bask-sb" id="acceptoffer" onclick="confirm('By clicking OK you are accepting the offer of £15.00 for your 1 item(s).'); acceptoffer();"/>]]></replacecontent></taconite>

然而,似乎存在一个问题。简单HTML Dom只适用于有效的标记,这是无效的。我能从这个结果中提取15000英镑的最好方法是什么。

谢谢。非常感谢。

仅使用有效标记,除非该标记被其他资源使用。

一种替代方案可以是使用strpos()/substr(),例如:

$price = substr($input,strpos($h, "$")); // or euro symbol whatever you need
$price = substr($x, 0, strpos($x, "<")); 

我假设您的输入设置为变量$input。

只有当您能够相当确定价格后的下一个字符将是<并且只有一个价格实例时,这才会很好地工作。如果有不止一个价格实例,您必须对其进行调整以获得正确的价格实例。