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 關注
- 202 瀏覽
添加回答
舉報