Home > Backend Development > PHP Tutorial > 求一段代码的正则解决方案

求一段代码的正则解决方案

WBOY
Release: 2016-06-13 10:29:08
Original
952 people have browsed it

求一段代码的正则
这2段代码是在html中,把html通过file_get_contents下载下来后提取其中的数据,网页地址:http://rate.taobao.com/user-rate-39512.htm

要获取最近半年和半年前的评价(好评,中评和差评),示例代码如下

我要同时匹配这两段字符,该如何写正则呢


4508530



289048

提示:
第一个的:class="J_MakePoint" data-point-val="tbrate.2.5.1">4508530
第二个的:class="J_show_list J_MakePoint" data-point-val="tbrate.2.4.1" data-param='timeLine=-210&result=1'>289048


都是需要提取标签内的数字,如第一个中搞定4508530和第二个中的289048,用一个正则匹配

------解决方案--------------------
三个一样的贴? class只要包含 J_MakePoint 就匹配?



------解决方案--------------------

PHP code
<?php $url='http://rate.taobao.com/user-rate-39512.htm';$data=file_get_contents($url);preg_match_all("/<a href\=\"http:\/\/ratehis.taobao.com\/user-rate-39512(.*)\" class\=\"J_MakePoint\" data\-point\-val\=\"(.*)\">(.*)/U",$data,$contents);echo '第一条数据:'.$contents[3][0].'<br>';echo '第二条数据:'.$contents[3][1].'<br>';echo '第三条数据:'.$contents[3][2].'<br>';?><div class="clear">
                 
              
              
        
            </div>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template