Php 预匹配问题
我有index.htmlPhp 预匹配问题,php,file-get-contents,Php,File Get Contents,我有index.html 呜呜呜呜 呜呜呜呜 我需要在body标签中获取内容。试过这个 <?php $site = file_get_contents("index.html"); preg_match("/<body[^>]*>(.*?) \/body>/is", $site, $matches); print ($matches[1]); ?> 但它不会输出任何东西。请告诉我这里的问题。谢谢。 <?php $site = file_get
呜呜呜呜
呜呜呜呜
我需要在body标签中获取内容。试过这个
<?php $site = file_get_contents("index.html"); preg_match("/<body[^>]*>(.*?) \/body>/is", $site, $matches); print ($matches[1]); ?>
但它不会输出任何东西。请告诉我这里的问题。谢谢。
<?php
$site = file_get_contents("index.html");
preg_match("/<body.*?>(.*?)<\/body>/is", $site, $matches);
print ($matches[1]);
?>
这可能不是您的答案,但我建议您尝试使用php DOMDocument“/]*>(.*)\/body>/is“
应该是“/]*>(.*)/is”
您应该看看php简单HTML DOM解析器:
你可以用这样的方法得到身体:
$html = file_get_html('index.html')
$body = $html->find('body');
然后,您可以通过以下方式获取内部HTML:
$content = $body->innertext;
(相关)建议的第三方替代方案,以代替实际使用的字符串解析:,和。