Home >Backend Development >PHP Tutorial >php正则匹配问题
$t='
$pre_reg = '/
$t='<tr><td><a href="/f?kw=chrome" title="chrome">chrome</a></td><tr><td><a href="/f?kw=%CA%A5%B0%B2%B5%" title="test">test</a></td>';$find='/href="\/f\?kw=([^"]*?)"\stitle="([^"]*?)"/s';preg_match_all($find,$t,$res);echo "<pre class="brush:php;toolbar:false">";print_r($res);echo "";/*Array( [0] => Array ( [0] => href="/f?kw=chrome" title="chrome" [1] => href="/f?kw=%CA%A5%B0%B2%B5%" title="test" ) [1] => Array ( [0] => chrome [1] => %CA%A5%B0%B2%B5% ) [2] => Array ( [0] => chrome [1] => test ))*/
$t='<tr><td><a href="/f?kw=chrome" title="chrome">chrome</a></td><tr><td><a href="/f?kw=%CA%A5%B0%B2%B5%" title="test">test</a></td>';$find='/href="\/f\?kw=([^"]*?)"\stitle="([^"]*?)"/s';preg_match_all($find,$t,$res);echo "<pre class="brush:php;toolbar:false">";print_r($res);echo "";/*Array( [0] => Array ( [0] => href="/f?kw=chrome" title="chrome" [1] => href="/f?kw=%CA%A5%B0%B2%B5%" title="test" ) [1] => Array ( [0] => chrome [1] => %CA%A5%B0%B2%B5% ) [2] => Array ( [0] => chrome [1] => test ))*/