http://www.so.com/s?ie=utf-8&src=360sou_home&q=csdn
我想匹配出这个页面每个搜索结果的“标题”、“URL"、“快照时间”,我这样写,匹配不出来呢,
$c1 = "/<h3 class=\"res-title \">\s<a href=\"(.*)\" data-st=\"[\d]\" data-e=\"[\d]\"  data-pos=\"[\d]\" data-m=\"[.*]\"  target=\"_blank\">(.*)<\/a>\s<\/h3>/Uis";
preg_match_all($c1,$content1,$arr1);
print_r($arr1);
php 正则表达式 匹配字符串

解决方案 »

  1.   

    $c1 = "/<h3 class=\"res-title \">\s<a href=\"(.*)\" data-st=\"[\d]\" data-e=\"[\d]\"  data-pos=\"[\d]\" data-m=\"[.*]\"  target=\"_blank\">(.*)<\/a>\s<\/h3>/Uis";
    为什么都只是 \s 而不是 \s* 呢?
    如果页面源于 window 系统,那么 \r\n 肯定就是 2 个了。况且 html 标记间为什么一定要有一个空白字符呢?
      

  2.   

    <a href="http://java.csdn.net/" data-st="0" data-e="1"  data-pos="10" data-m="222fd4e02add8f3b3b1d7e622d68c3ee"  target="_blank">
    JAVA频道 - <em>CSDN</em>.NET</a>如何与你的 data-pos=\"[\d]\" 匹配?
      

  3.   

    改成这样也不行:$c1 = "/<h3 class=\"res-title \">[\s*]<a href=\"(.*)\" data-st=\"[\d+]\" data-e=\"[\d+]\"  data-pos=\"[\d+]\" data-m=\"[.*]\"  target=\"_blank\">(.*)<\/a>[\s*]<\/h3>/Uis";
      

  4.   

    $c1 = "/<h3 class=\"res-title \">\s*<a href=\"(.*)\" data-st=\"[\d+]\" data-e=\"[\d+]\"  data-pos=\"[\d+]\" data-m=\"[.*]\"  target=\"_blank\">(.*)<\/a>\s*<\/h3>/Uis";这样?也不行呢
      

  5.   

    我想这样把标题部分匹配出来,接过第一条没匹配出来,只匹配了9条,正常应该是10条才对。$c1 = "/<h3 class=\"res-title [-nowrap]?\">(.*)<\/h3>/Uis";
      

  6.   

    $c1 = "/<h3 class=\"res-title [\-nowrap]?\">(.*)<\/h3>/Uis";这样也不行,不知错在哪了