php从html页面中提取信息
我有这段代码
<input type=hidden name="code1" value="AA-T5301">
<tr>
<td align=left valign=middle class="stdtext">
AA-T5301
</a>
</td>
<td valign=middle align=left class="stdtext">
<a onMouseOver="window.status='See the more info on '; return true"
HREF="product.asp?ms=&dept_id=322&sku=32&nav=">
Grapeseed Oil 150ml
</A>
</td>
<td valign=middle align=right class="stdtext">Order Now</td>
<td valign=middle align=right class="stdtext">
<font class="productsale">
<strike>£3.04</strike>
 
</font>
£2.04
</td>
<td valign=middle align=right class="stdtext">
<input type=text size=4 name="qty_AA-T5301" value="0">
</td>
</tr>
<input type=hidden name="code2" value="AA-T5302">
<tr>
<td align=left valign=middle class="stdtext">
AA-T5302
</a>
</td>
<td valign=middle align=left class="stdtext">
<a onMouseOver="window.status='See the more info on '; return true"
HREF="product.asp?ms=&dept_id=322&sku=143&nav=">
Grapeseed Oil 500ml
</A>
</td>
<td valign=middle align=right class="stdtext">Order Now</td>
<td valign=middle align=right class="stdtext">
<font class="productsale">
<strike>£6.46</strike>
 
</font>
£4.33
</td>
<td valign=middle align=right class="stdtext">
<input type=text size=4 name="qty_AA-T5302" value="0">
</td>
</tr>
<input type=hidden name="code3" value="AA-T530">
<tr>
<td align=left valign=middle class="stdtext">
AA-T530
</a>
</td>
<td valign=middle align=left class="stdtext">
<a onMouseOver="window.status='See the more info on '; return true"
HREF="product.asp?ms=&dept_id=322&sku=19&nav=">
Grapeseed Oil 50ml
</A>
</td>
<td valign=middle align=right class="stdtext">Out of Stock</td>
<td valign=middle align=right class="stdtext">
<font class="productsale">
<strike>£1.75</strike>
 
</font>
£1.17
</td>
<td valign=middle align=right class="stdtext">
<input type=text size=4 name="qty_AA-T530" value="0">
</td>
</tr>
我怎样才能将信息提取到一个数组中,所以我有这样的东西..
product_code_array=(AA-T5301,AA-T5302,AA-T530);
RRP_array=(3.04,6.46,1.75);
price_array=(2.04,4.33,1.17);
注意:页面上一次可能有超过 3 个项目,或者可能只有 1 个
I have this code
<input type=hidden name="code1" value="AA-T5301">
<tr>
<td align=left valign=middle class="stdtext">
AA-T5301
</a>
</td>
<td valign=middle align=left class="stdtext">
<a onMouseOver="window.status='See the more info on '; return true"
HREF="product.asp?ms=&dept_id=322&sku=32&nav=">
Grapeseed Oil 150ml
</A>
</td>
<td valign=middle align=right class="stdtext">Order Now</td>
<td valign=middle align=right class="stdtext">
<font class="productsale">
<strike>£3.04</strike>
</font>
£2.04
</td>
<td valign=middle align=right class="stdtext">
<input type=text size=4 name="qty_AA-T5301" value="0">
</td>
</tr>
<input type=hidden name="code2" value="AA-T5302">
<tr>
<td align=left valign=middle class="stdtext">
AA-T5302
</a>
</td>
<td valign=middle align=left class="stdtext">
<a onMouseOver="window.status='See the more info on '; return true"
HREF="product.asp?ms=&dept_id=322&sku=143&nav=">
Grapeseed Oil 500ml
</A>
</td>
<td valign=middle align=right class="stdtext">Order Now</td>
<td valign=middle align=right class="stdtext">
<font class="productsale">
<strike>£6.46</strike>
</font>
£4.33
</td>
<td valign=middle align=right class="stdtext">
<input type=text size=4 name="qty_AA-T5302" value="0">
</td>
</tr>
<input type=hidden name="code3" value="AA-T530">
<tr>
<td align=left valign=middle class="stdtext">
AA-T530
</a>
</td>
<td valign=middle align=left class="stdtext">
<a onMouseOver="window.status='See the more info on '; return true"
HREF="product.asp?ms=&dept_id=322&sku=19&nav=">
Grapeseed Oil 50ml
</A>
</td>
<td valign=middle align=right class="stdtext">Out of Stock</td>
<td valign=middle align=right class="stdtext">
<font class="productsale">
<strike>£1.75</strike>
</font>
£1.17
</td>
<td valign=middle align=right class="stdtext">
<input type=text size=4 name="qty_AA-T530" value="0">
</td>
</tr>
How can i extract the info into an array so i have something like this..
product_code_array=(AA-T5301,AA-T5302,AA-T530);
RRP_array=(3.04,6.46,1.75);
price_array=(2.04,4.33,1.17);
Note: There maybe more than 3 items on a page at a time or there may only be 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试使用 DOMDocument 类,但您必须修复您的 html。您有结束链接标记 (
),但没有任何开始链接标记 (
)
You can try and use the DOMDocument class, but you have to fix your html. You have end link tags (
</a>
) without any start link tags (<a href="">
)首先看一下这段代码:
您也可以根据需要直接查找或查找。根据页面的布局,您可能想要使用“更高”的节点,以便您根据标签参数或标签位置知道自己所在的位置。
Look at this code for a start:
You can also directly go for or just as you need it. Depending on the layout of your page you might want to go for a "higher" node so you know where you are based on tag parameters or the tag position.