日期:2014-05-17 浏览次数:20437 次
<td class="image"> <a href="/title/tt0948470/" title="The Amazing Spider-Man (2012)"><img src="http://ia.media-imdb.com/images/M/MV5BMjMyOTM4MDMxNV5BMl5BanBnXkFtZTcwNjIyNzExOA@@._V1._SX54_CR0,0,54,74_.jpg" height="74" width="54" alt="The Amazing Spider-Man (2012)" title="The Amazing Spider-Man (2012)"></a> </td>
<?php $str='<td class="image"> <a href="/title/tt0948470/" title="The Amazing Spider-Man (2012)"><img src="http://ia.media-imdb.com/images/M/MV5BMjMyOTM4MDMxNV5BMl5BanBnXkFtZTcwNjIyNzExOA@@._V1._SX54_CR0,0,54,74_.jpg" height="74" width="54" alt="The Amazing Spider-Man (2012)" title="The Amazing Spider-Man (2012)"></a> <a href="/title/tt0948470/" title="The Amazing Spider-Man (2012)"> </td>'; $patten = '/title="(.*)"/Uis'; if (preg_match ( $patten, $str, $array )) { print_r($array); } echo "<br>"; $patten1 = '/<a href=".*" title="(.*)">/Uis'; if (preg_match_all ( $patten1, $str, $array1 )) { print_r($array1[1]); } ?>
------解决方案--------------------
$string='<td class="image"><a href="/title/tt0948470/" title="The Amazing Spider-Man (2012)1"><img src="http://ia.media-imdb.com/images/M/MV5BMjMyOTM4MDMxNV5BMl5BanBnXkFtZTcwNjIyNzExOA@@._V1._SX54_CR0,0,54,74_.jpg" height="74" width="54" alt="The Amazing Spider-Man (2012)" title="The Amazing Spider-Man (2012)3"></a><a href="/title/tt0948470/" title="The Amazing Spider-Man (2012)2"></td>'; if (preg_match_all ( '/(?<=\s)title="(.*)"/Ui', $string, $arr )) { var_dump($arr); } /* <br>array(2) { [0]=> array(3) { [0]=> string(38) "title="The Amazing Spider-Man (2012)1"" [1]=> string(38) "title="The Amazing Spider-Man (2012)3"" [2]=> string(38) "title="The Amazing Spider-Man (2012)2"" } [1]=> array(3) { [0]=> string(30) "The Amazing Spider-Man (2012)1" [1]=> string(30) "The Amazing Spider-Man (2012)3" [2]=> string(30) "The Amazing Spider-Man (2012)2" } } */