Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 预匹配问题_Php_File Get Contents - Fatal编程技术网

Php 预匹配问题

Php 预匹配问题,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

我有index.html


呜呜呜呜
呜呜呜呜

我需要在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;

(相关)建议的第三方替代方案,以代替实际使用的字符串解析:,和。