<div class="c_list">
       <ul>
          <li>·<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a></li>
          <li>·<a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a></li>
          <li>·<a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a></li>
        </ul>
用正则获取出每个li中<a></a> 之间数据,不知道哪出错了,有点乱,希望高手指点下
我写了没有数据
$pattern = "/^<div class=\"c_list\">([\r\n][\s]+)<ul>([\r\n][\s]+)<li>·(<([\w]+)[^>]*>)(.*)(<\/\\2>)/";
         preg_match_all($pattern, $results,$matches);
echo '<pre>';
        var_dump($matches);

解决方案 »

  1.   

    $s = <<< HTML
    <div class="c_list">
           <ul>
              <li>·<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a></li>
              <li>·<a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a></li>
              <li>·<a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a></li>
            </ul>HTML;$p = '/<a.+<\/a>/isU';preg_match_all($p, $s, $r);
    print_r($r);
    Array
    (
        [0] => Array
            (
                [0] => <a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a>
                [1] => <a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a>
                [2] => <a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a>
            ))
      

  2.   

    首先感先1楼的回复,1楼可以配出<a></a>当中的值,但是这样也会把其他的<a></a>也存进来了(我这个主要是抓取页面的数据之用)我只想知道比如如下这段html,假设class="c_list"//这个class唯一的情况下的这段div块中<a></a>当中的值,谢谢大家,
    <div class="c_list">
           <ul>
              <li>·<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a></li>
              <li>·<a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a></li>
              <li>·<a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a></li>
            </ul>
      

  3.   


    $str=<<< EOF
    <div class="c_list">
           <ul>
              <li>·<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a></li>
              <li>·<a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a></li>
              <li>·<a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a></li>
            </ul>
         
    EOF;
           preg_match("/<div\s+class=\"c_list\">.+<\/ul>/isU",$str,$matchs);
           preg_match_all('/<a.+<\/a>/isU',$matchs[0],$arr);
           print_r($arr);
    Array
    (
        [0] => Array
            (
                [0] => <a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a>
                [1] => <a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a>
                [2] => <a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a>        ))
      

  4.   


    $str = <<<STR
    <div class="c_list">
           <ul>
              <li>·<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a></li>
              <li>·<a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a></li>
              <li>·<a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a></li>
            </ul>STR;
    preg_match_all('/<a[^>]*>(.*)<\/a>/Ui', $str, $matches);
    print_r($matches[1]);
    /*
    输出结果:
    Array
    (
        [0] => 111<b class="ger_1">1</b>硬功夫
        [1] => 222<b class="ger_1">2</b> 左在 
        [2] => 333<b class="ger_1">3</b>在地 
    )*/
      

  5.   


    $str = '<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a>';
    preg_match_all("/<[\w]+[^>]*>(.*)<[\w]+[^>]*>(.*)<\/b>(.*)<\/a>/isU",$str,$arr);
    echo '<pre>';
    print_r($arr);Array
    (
        [0] => Array
            (
                [0] => 1111硬功夫
            )    [1] => Array
            (
                [0] => 111
            )    [2] => Array
            (
                [0] => 1
            )    [3] => Array
            (
                [0] => 硬功夫
            ))
    /怎么写可以取得上面这样的结果,参照了下php手册的写法,但是对整个的写法还不是很清楚,要明了点,最好能带点注释,谢谢
    <div class="c_list">
           <ul>
              <li>·<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a></li>
              <li>·<a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a></li>
              <li>·<a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a></li>
            </ul>
      

  6.   

    最好是每个<li></li>中的值对应一个array