1 回答

TA贡献1851条经验 获得超4个赞
使用 positive look ahead 检查是否有结束head标签
$content = "<html>
<head>
<style>something</style>
<style class='my-class'>other</style>
</head>
<body>
<style>content</style>
</body>
</html>";
preg_match_all('#(<style.*>(.*)</style>)(?=.*</head>)#Usmi', $content, $matches);
print_r($matches);
给我
Array
(
[0] => Array
(
[0] => <style>something</style>
[1] => <style class='my-class'>other</style>
)
[1] => Array
(
[0] => <style>something</style>
[1] => <style class='my-class'>other</style>
)
[2] => Array
(
[0] => something
[1] => other
)
)
- 1 回答
- 0 关注
- 184 浏览
添加回答
举报