$str = '<td itemprop="ProductID">
<h1>AN41908A-VB</h1>
</td>';preg_match("/<td itemprop=\"ProductID\"><h1>(.*?)<\/h1><\/td>/is", $str,$name);
print_r($name);
为什么打印数组是空的
Array ( ) 

解决方案 »

  1.   

    因为> <在str中间有换行符,你没匹配
      

  2.   

    为什么不空呢?
    <h1>前和</h1>后不是都有换行符吗?preg_match("/<td itemprop=\"ProductID\">.*<h1>(.*?)<\/h1>.*<\/td>/is", $str,$name);
      

  3.   

    preg_match("/<td itemprop=\"ProductID\">\s+<h1>(.*?)<\/h1>\s+<\/td>/is", $str,$name);
      

  4.   

    preg_match("/<td itemprop=\"ProductID\">\n+<h1>(.*?)<\/h1>\n+<\/td>/is", $str,$name); 
      

  5.   

    preg_match('/<td itemprop="ProductID[\w\W]*?h1>(.*?)</i',  $str,$name);