作者kuoll (kuoll)
看板PHP
标题[请益] preg_match_all可否截取这样的字串?
时间Sun Apr 13 21:12:12 2014
原始字串:
*****<tag>****<tag>********
我想要截取第一个<tag>前後字串:
「*****」以及「****<tag>******」
所以我下了preg_match_all('/(.*)<tag>(.*)/', 原始字串, $out);
echo $out[1][0];
echo $out[2][0];
结果抓到的是:
「*****<tag>****」以及「******」
看起来是以最後一个<tag>作切割
请问该如何修改正规式?
还是有其它更合适function?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 220.129.30.240
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/PHP/M.1397394734.A.F2B.html
1F:→ bibo9901:(.*?)<tag>(.*) 04/13 21:50
2F:→ bibo9901:不过直接用 explode("<tag>", $str, 2 ) 应该更快 04/13 21:51
3F:→ kuoll:方法有效 非常感谢! 04/13 22:00