如何使用PHP从HTML中提取或过滤掉信息?

时间:2015-05-04 14:13:21

标签: php html filter

我每天都会收到一封包含html文档的电子邮件,其中包含前一天的统计信息。这个HTML很难为所有用户阅读,所以我想从这个表中提取信息"自动"用PHP脚本。我将源代码放在这里,我只编辑敏感信息。这些线条是无尽的#34;所以我只包括几行,这样你就可以看到这个想法。

只是为了让您了解我想要什么或需要什么,就是将大量信息捆绑在一起,并使其成为可搜索的"在PHP中,所以我可以创建自己的信息自定义视图。如果是那天有3个卖家,而不是50行商品,它将是3行,其中它表示商品的数量而不是每件商品。

<html  dir="ltr"><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>Outdata of rapport</title>                                                                                                                                      <style>table.list    { border-collapse: collapse; }</style>                                                                                                                                                                                                    </head>                                                                                                                                                                                                                                                        <!script!>                                                                                                                                                                                                                                                     <body bgcolor="#E8EAD8">                                                                                                                                                                                                                                       <blockquote>                                                                                                                                                                                                                                                   <p align=left><font size=+2><b> </b></font></p>                                                                                                                                                                                                                <p align=left>                                                                                                                                                                                                                                                 <font style="font-family:monospaced"> <table  class="list" border=1 cellspacing=0 cellpadding=1 rules=groups borderColor=black ><colgroup><colgroup>  <tbody><tr><td style= background:#5dcbfd ><font face="courier new" size="2"><nobr   id=l0002003>Data statistic&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#5dcbfd ><font face="courier new" size="2"><nobr   id=l0002030>Numbers</nobr></font></td>  </tr>  <tbody><tr><td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0004003>Transfered&nbsp;posts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0004030>&nbsp;&nbsp;&nbsp;140</nobr></font></td>  </tr>  <tr><td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0005003>Defined&nbsp;sum lines</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0005030>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1</nobr></font></td>  </tr>  <tbody></tbody></table> <table  class="list" border=1 cellspacing=0 cellpadding=1 rules=groups borderColor=black ><colgroup><colgroup><colgroup><colgroup><colgroup><colgroup><colgroup><colgroup><colgroup><colgroup><colgroup>  <tbody><tr><td style= background:#5dcbfd ><font face="courier new" size="2"><nobr   id=l0008003>&nbsp;Date&nbsp;</nobr></font></td>  <td style= background:#5dcbfd ><font face="courier new" size="2"><nobr   id=l0008015>Group</nobr></font></td>  <td style= background:#5dcbfd ><font face="courier new" size="2"><nobr   id=l0008026>Varegrp.betegn.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#5dcbfd ><font face="courier new" size="2"><nobr   id=l0008047>Ware</nobr></font></td>  <td style= background:#5dcbfd ><font face="courier new" size="2"><nobr   id=l0008056>Ware text&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#5dcbfd ><font face="courier new" size="2"><nobr   id=l0008097>Seller&nbsp;&nbsp;</nobr></font></td>  <td style= background:#5dcbfd ><font face="courier new" size="2"><nobr   id=l0008106>Name&nbsp;seller&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#5dcbfd ><font face="courier new" size="2"><nobr   id=l0008132>Fil.</nobr></font></td>  <td style= background:#5dcbfd ><font face="courier new" size="2"><nobr   id=l0008137>Name&nbsp;on&nbsp;filial&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#5dcbfd ><font face="courier new" size="2"><nobr   id=l0008168>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DB</nobr></font></td>  <td style= background:#5dcbfd ><font face="courier new" size="2"><nobr   id=l0008179>NumPos</nobr></font></td>  </tr>  <tbody><tr><td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0010003>&nbsp;30.04.2015</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0010015>030001&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0010026>Mobile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0010047>10038&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0010056>&nbsp;&nbsp;&nbsp;4G,&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0010097>99999999</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0010106>Seller&nbsp;Two&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0010132>0171</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0010137>Store&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0010168>&nbsp;1.000,40&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0010179>&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;</nobr></font></td>  </tr>  <tr><td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0011003>&nbsp;30.04.2015</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0011015>030001&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0011026>Mobile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0011047>10038&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0011056>&nbsp;&nbsp;4G,&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0011097>99999999</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0011106>Seller&nbsp;One&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0011132>0171</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0011137>Store&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0011168>&nbsp;&nbsp;&nbsp;480,20&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0011179>&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;</nobr></font></td>  </tr>  <tr><td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0012003>&nbsp;30.04.2015</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0012015>030306&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0012026>Protection&nbsp;Mobile&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0012047>10793&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0012056>&nbsp;Wallet&nbsp;Case&nbsp;&nbsp;for&nbsp;Galaxy&nbsp;S5&nbsp;bl</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0012097>99999999</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0012106>Seller&nbsp;One&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0012132>0171</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0012137>Store&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0012168>&nbsp;&nbsp;&nbsp;195,20&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0012179>&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;</nobr></font></td>  </tr>  <tr><td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0013003>&nbsp;30.04.2015</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0013015>030306&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0013026>Protection&nbsp;Mobile&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0013047>10794&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0013056>&nbsp;Slim&nbsp;Wallet&nbsp;Case&nbsp;Galaxy&nbsp;S5,&nbsp;Brown</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0013097>99999999</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0013106>Seller&nbsp;Two&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0013132>0171</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0013137>Store&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0013168>&nbsp;&nbsp;&nbsp;190,20&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0013179>&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;</nobr></font></td>  </tr>  <tr><td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0014003>&nbsp;30.04.2015</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0014015>030304&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0014026>Charger&nbsp;Mobile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0014047>10865&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0014056>&nbsp;TravelCharger&nbsp;Micro&nbsp;USB,&nbsp;Black&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0014097>99999999</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0014106>Seller&nbsp;One&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0014132>0171</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0014137>Store&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0014168>&nbsp;&nbsp;&nbsp;180,20&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0014179>&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;</nobr></font></td>  </tr>  <tr><td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0015003>&nbsp;30.04.2015</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0015015>030306&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0015026>Protection&nbsp;Mobile&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0015047>11092&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0015056>&nbsp;Slim&nbsp;Wallet&nbsp;Case&nbsp;f&nbsp;Xperia&nbsp;Z3&nbsp;Comp</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0015097>99999999</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0015106>Seller&nbsp;One&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0015132>0171</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0015137>Store&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0015168>&nbsp;&nbsp;&nbsp;250,20&nbsp;</nobr></font></td>  <td style= background:#d7ecf4 ><font face="courier new" size="2"><nobr   id=l0015179>&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;</nobr></font></td>  </tr>  <tr><td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0016003>&nbsp;30.04.2015</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0016015>030306&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0016026>Protection&nbsp;Mobile&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0016047>11099&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0016056>&nbsp;Slim&nbsp;Wallet&nbsp;Case&nbsp;f&nbsp;Xperia&nbsp;Z3&nbsp;blac</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0016097>99999999</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0016106>Seller&nbsp;One&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0016132>0171</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0016137>Store&nbsp;&nbsp;&nbsp;&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0016168>&nbsp;&nbsp;&nbsp;170,20&nbsp;</nobr></font></td>  <td style= background:#eef9ff ><font face="courier new" size="2"><nobr   id=l0016179>&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;</nobr></font></td>  </tr><tbody></tbody></table>                                                                                                                                                                          </p>                                                                                                                                                                                                                                                           </blockquote>                                                                                                                                                                                                                                                  </body>                                                                                                                                                                                                                                                        </html>

1 个答案:

答案 0 :(得分:0)

使用Document Object Model:

同时查看此答案:PHP Parse HTML code