简单的php dom解析器不适用于本地URL

时间:2014-03-10 09:24:02

标签: php parsing dom

不适用于此网址。问题是什么? 获取错误 - PHP注意:尝试获取非对象的属性

<?php
include ('config.php');
include('simple_html_2012.php');
echo file_get_html('http://www.localhost/test/test.html')->plaintext; 
?>

如果尝试解析google.com,一切正常。

2 个答案:

答案 0 :(得分:3)

echo file_get_html('http://localhost/test/test.html')->plaintext;

echo file_get_html('http://127.0.0.1/test/test.html')->plaintext;

答案 1 :(得分:0)

可能会有所帮助:

    if($source = file_get_contents("http://localhost/test/test.html"))
    {
        $html = str_get_html($source);
        echo $html->plaintext;
    }
    else
    {
        echo "Something wrong!";
    }