Php 我应该使用正则表达式来解析这个html表数据字符串吗?

Php 我应该使用正则表达式来解析这个html表数据字符串吗?,php,parsing,html-parsing,php-parser,Php,Parsing,Html Parsing,Php Parser,解析这些数据的最佳方法是什么?我应该用正则表达式还是别的什么?数据是html格式的,但我是从一个网站上找到的,我将解析这个字符串,并且只解析这个字符串(注意:字符串要长得多-超过1300个实例-下面只有两个)-注意我在大多数web编程中使用php和jquery 我只需要提取第二个td中的数据,并且只提取锚内的锚文本——在实例1中,它是:Best,Jahvid DET RB 我只需要运行这个循环一次 <tr class="oddtablerow"><td class="rank"

解析这些数据的最佳方法是什么?我应该用正则表达式还是别的什么?数据是html格式的,但我是从一个网站上找到的,我将解析这个字符串,并且只解析这个字符串(注意:字符串要长得多-超过1300个实例-下面只有两个)-注意我在大多数web编程中使用php和jquery

我只需要提取第二个td中的数据,并且只提取锚内的锚文本——在实例1中,它是:Best,Jahvid DET RB

我只需要运行这个循环一次

<tr class="oddtablerow"><td class="rank">1.</td><td class="rank">1.</td><td class="player"><a href="http://football22.myfantasyleague.com/2010/player?L=34793&amp;P=9839"  title="Salary: $2250000, Year: 3, Status: 3, Info: Drafted 10 1:04 Team, Week 3: at Vikings Sun 1:00 p.m. ET" class="position_rb">Best, Jahvid DET RB</a> (R) </td><td class="points tot">53.90</td><td class="points avg">26.950</td><td class="points"><a href="detailed?L=34793&amp;W=1&amp;P=9839&amp;YEAR=2010">17.55</a></td> 
<td class="points"><a href="detailed?L=34793&amp;W=2&amp;P=9839&amp;YEAR=2010">36.35</a></td> 
<td class="status"><a title="Owner: William Gold"  class="franchise_0009" href="http://football22.myfantasyleague.com/2010/options?L=34793&amp;F=0009&amp;O=01">Team Name</a> - <a href="options?L=34793&amp;O=05&amp;FRANCHISE=0013,0009&amp;PLAYER=9839,">Trade</a></td><td class="week">7</td><td class="salary">$2250000</td></tr> 
<tr class="eventablerow myfranchise "><td class="rank">2.</td><td class="rank">2.</td><td class="player"><a href="http://football22.myfantasyleague.com/2010/player?L=34793&amp;P=3291"  title="Salary: $7400000, Year: 3, Status: 3, Info: , Week 3: at Broncos Sun 4:15 p.m. ET" class="position_qb">Manning, Peyton IND QB</a></td><td class="points tot">49.61</td><td class="points avg">24.805</td><td class="points"><a href="detailed?L=34793&amp;W=1&amp;P=3291&amp;YEAR=2010">26.66</a></td> 
<td class="points"><a href="detailed?L=34793&amp;W=2&amp;P=3291&amp;YEAR=2010">22.95</a></td> 
<td class="status"><a title="Owner: Robert M. Cavezza "  class="myfranchise franchise_0013" href="http://football22.myfantasyleague.com/2010/options?L=34793&amp;F=0013&amp;O=01">The Bullies</a></td><td class="week">7</td><td class="salary">$7400000</td></tr> 
1.1。(R) 53.9026.950
- 7$2250000 
2.2.49.6124.805 
7$7400000 

Edit:jquery答案发生了什么变化?我正要实现它,但它消失了

如果您正在寻找执行速度最快的解决方案,它就是最快的XML解析器之一。它比其他解决方案(如)更难使用,但由于您需要解析大量条目,性能可能很重要

否则使用起来相当简单。你可以找到一个简单的例子,说明如何使用我在另一个问题上给出的

如果您想以字符串形式加载内容,请按以下方式操作:

XMLReader

$foo = new XMLReader();
$foo->xml($yourStringHere);
DOMDocument

$foo = new DOMDocument();
$foo->loadHTML($yourStringHere);

正则表达式和HTML?你在正确的网站上:)这可能是网站上最多的。你最好使用一个合适的工具并从中提取信息。有没有办法查看被管理员或作者删除的旧答案?它是由作者删除的,而jQuery与PHP完全无关这可能就是它被删除的原因。废话-找不到缓存的答案?要使用这些xml阅读器,我是否需要将此数据更改为xml对象,然后解析代码?或者我可以将这些数据作为php字符串来解析xml吗?我将一个html从网站复制并粘贴到一个字符串中-因此该字符串被认为是xml还是我必须构建一个domdocument在您的示例中,您使用domdocument和一个html文件-我将使用一个html字符串,我是否应该将引用的文本放在该脚本中get_file_contents函数所在的位置?@Bob查看我的编辑,了解如何将数据作为字符串加载到XMLReader和domdocument中。