Home > Backend Development > PHP Tutorial > 正则表达式匹配,该如何处理

正则表达式匹配,该如何处理

WBOY
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"却是这个,多了引号,匹配不到。
  • 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 Recommendations
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template