2014-12-02 55 views
-1

Websiste包含像下面的一些代码..预浸匹配多行不工作

</span></td> 
    <td width="1%" align="right" nowrap="nowrap" class="small inner" >190 MB</td> 
    <td width="1%" align="center" nowrap="nowrap" class="small inner" >15</td> 

我需要得到190MB

我试过下面code..tried/S,/ M没有什么作品。 。

preg_match_all('/<\/td> 
    <td width="1%" align="right" nowrap="nowrap" class="small inner" >(.*?)<\/td>/m',$lol,$cooler); 
+0

您是否尝试过g [http://regex101.com/r/wR0yN5/1](regex101) – ehwas 2014-12-02 20:17:36

+0

全局修饰符隐含在reg_match_all函数中。 – 2014-12-02 20:20:09

回答

1
$lol = '</span></td> 
<td width="1%" align="right" nowrap="nowrap" class="small inner" >190 MB</td> 
<td width="1%" align="center" nowrap="nowrap" class="small inner" >15</td>';  

preg_match_all('/(?<=\<\/span\>\<\/td\>)[\n]?.*((?<=\>).+(?=\<))/', $lol, $cooler); 

echo $cooler[1][0]; //Outputs "190 MB" 

http://regex101.com/r/jY1pY9/1

+0

我想只有190MB。我需要配合新lline – 2014-12-02 20:26:29

+0

还好,见上面 – 2014-12-02 20:37:14

2

Ew,用正则表达式解析HTML。从来不是一个好主意。

由于看起来没有任何方便的标识符,解析器可以帮助您进入,为什么不只是preg_match("/\d+\s*[KMG]B/,$ lol,$ match); echo $ match [0];`?尽可能保持简单。

+0

编辑有MB GB KB – 2014-12-02 20:28:18

+0

然后相应地更新正则表达式,如我在回答刚才做。 – 2014-12-02 20:31:57