正则表达式匹配,该如何处理
Release: 2016-06-13 12:55:45
Original
960 people have browsed it
正则表达式匹配
想用正则表达式匹配这种格式
新闻中心
<br />
<?php<br />
<br />
<br />
<br />
$con= file_get_contents("http://17173.com");<br />
<br />
$preg = '#<LI><A href="(.*)" target="_blank">(.*)</A>#';<br />
<br />
preg_match_all($preg, $con, $arr); <br />
<br />
//print_r($arr[1]);<br />
<br />
foreach($arr[1] as $id=>$v){<br />
<br />
echo "<a href=$v>".$v."</a> ".$arr[2][$id]."<br>";<br />
<br />
}<br />
<br />
?><br />
<br />
Copy after login
匹配结果是没东西,但是这个页面中是有这种格式链接的,求解
------解决方案--------------------首先 target="_blank"和上面给出的是不符合的,到底是哪个?
然后再echo $con;看看
确定有期望的内容
再注意大小写和换行的问题――你的正则固定了大小写,圆点是不包含换行的
------解决方案--------------------preg_match_all('/
(.*?)/i', $str, $matches);
var_dump($matches[1]);
你的问题是:人家网站的内容是target=_blank这样的,而你的target="_blank"却是这个,多了引号,匹配不到。
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31