Home > Backend Development > PHP Tutorial > php正则匹配问题

php正则匹配问题

WBOY
Release: 2016-06-23 13:52:07
Original
965 people have browsed it

$t='

chrome
test
';
$pre_reg = '/ .*? preg_match_all($pre_reg,$t,$matches);
print_r($matches);

$t我省略了其他的,只留下了主要信息,但即便如此还是无法输出,请问这是什么问题
(我的原意是匹配 chrome 中的D8%C1%D0%CB%B9和chrome)


回复讨论(解决方案)

$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 "
Copy after login
Copy after login
";/*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 "
Copy after login
Copy after login
";/*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 ))*/


似乎还是不对,这是我原本的数据:

管理我喜欢的吧_百度贴吧

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
吧名 经验值 等级 取消关注
chrome6960php正则匹配问题
php正则匹配问题gtabbs5740php正则匹配问题
圣安地列斯5096
我需要的内容就是这两个xx的内容,请问如何匹配

是对的啊

$str=file_get_contents('test.txt');$find='/href="\/f\?kw=([^"]*?)"\stitle="([^"]*?)"/s'; preg_match_all($find,$str,$res); echo "<pre class="brush:php;toolbar:false">";print_r($res);echo "
Copy after login
";/*Array( [0] => Array ( [0] => href="/f?kw=chrome" title="chrome" [1] => href="/f?kw=gtabbs" title="gtabbs" [2] => href="/f?kw=%CA%A5%B0%B2%B5%D8%C1%D0%CB%B9" title="圣安地列斯" ) [1] => Array ( [0] => chrome [1] => gtabbs [2] => %CA%A5%B0%B2%B5%D8%C1%D0%CB%B9 ) [2] => Array ( [0] => chrome [1] => gtabbs [2] => 圣安地列斯 ))*/