我正在使用简单的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"> </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只适用于有效的标记,这是无效的。从这个结果中提取is 15.00的最好方法是什么?
谢谢。非常感谢。
发布于 2013-07-12 23:03:28
仅使用有效的标记,除非该标记由其他资源使用。
一种替代方法是使用strpos()/substr(),例如:
$price = substr($input,strpos($h, "$")); // or euro symbol whatever you need
$price = substr($x, 0, strpos($x, "<")); 我假设您的输入被设置为变量$input。
只有当您相当确定价格后的下一个字符将是一个<并且只有一个价格实例时,这才能很好地工作。如果将有多个价格实例,则必须调整它以获得正确的实例。
https://stackoverflow.com/questions/17616462
复制相似问题