我想提取html body
标记中包含的字符串。
示例输入:
<html>
<head>
</head>
<body style="color:red" >
hello
<p>test</p>
<div>how r u</div>
</body>
</html>
输出:
style="color:red"
我需要首先出现>
我在preg_match中使用了这个/body(.*)> /
答案 0 :(得分:0)
<?php
$sourcestring="your source string";
preg_match_all('/style="(.*?)"/is',$sourcestring,$matches);
echo "<pre>".print_r($matches,true);
?>
答案 1 :(得分:0)
也许是这样的
$html = '<html>
<head></head>
<body class="home blog" style="color:red;">
example
<p> test </p>
</body>
';
$tes = preg_match('/\<body(.*?)\>/', $html, $match);
echo $match[1];
将输出
class="home blog" style="color:red;"