php preg_match_all() 取消子模式

<?php
header("Content-type:text/html;charset=utf-8");
  //取消子模式
  $string='<td><a href="http://www.baidu.com">百度</a></td>';

  $preg='/<td><a href="([\s\S]*?)">([\s\S]*?)<\/a><\/td>/';

  if(preg_match_all($preg,$string,$matches)){
      var_dump($matches[0]);
      echo "<br/>";
     var_dump($matches[1]);
      echo "<br/>";
      var_dump($matches[2]);
  }else{
   echo "没有匹配到";
  } 
?>

对比:

<?php
header("Content-type:text/html;charset=utf-8");
//取消子模式
$string='<td><a href="http://www.baidu.com">百度</a></td>';

$preg='/<td><a href="(?:[\s\S]*?)">([\s\S]*?)<\/a><\/td>/';

if(preg_match_all($preg,$string,$matches)){
var_dump($matches[0]);
echo "<br/>";
var_dump($matches[1]);
}else{
echo "没有匹配到";
}
?>

取消子模式----->?:

你可能感兴趣的:(php preg_match_all() 取消子模式)