【发布时间】:2017-04-14 01:54:48
【问题描述】:
试图捕获标签之间的所有文本。
代码:
$test = '<test>foo<tests> asdlkfjklas lkflsdakj <test>sdfsd<tests> asdlkaskl <test>235234<tests>';
$match = '/<test>(.*)<tests>/';
preg_match_all($match, $test, $nextLink);
print_r 的结果:
Array ( [0] => Array ( [0] => foo asdlkfjklas lkflsdakj sdfsd asdlkaskl 235234 ) [1] => Array ( [0] => foo asdlkfjklas lkflsdakj sdfsd asdlkaskl 235234 ) )
【问题讨论】:
-
使用非贪婪量化
(.*?) -
结果不包括所有
<test>和<tests>之间的所有内容吗? -
使用查看源代码查看它实际返回的内容,因为浏览器隐藏了看起来像 HTML 标记的内容。
标签: php html regex preg-match preg-match-all