【问题标题】:Error when trying to get output in txt file Notice: Trying to get property of non-object in C:\xampp\htdocs\尝试在 txt 文件中获取输出时出错注意:尝试在 C:\xampp\htdocs\ 中获取非对象的属性
【发布时间】:2014-07-06 04:46:27
【问题描述】:

试图从一个新闻网站提取新闻详细信息的内容并在文本文件中获取输出,但出现错误“注意:尝试获取 C:\xampp\htdocs\folder4\test3 中非对象的属性。 php on line 8"。但是我要提取的新闻内容可以显示在浏览器上,问题是无法提取输出文本文件中的内容。

请帮我看看这段代码有什么问题(第 8 行)

1 <?php
2 include_once("simple_html_dom.php");
3 $html = file_get_html("http://www.newzx.com");
4 $content1= $html->find("div.mid-col div.news-box", 0);
5 $content2= $html->find("div.mid-col div.news-box", 1);
6 $con=$content1.$content2;
7 echo = $con;
8 file_put_contents(dirname(__FILE__) . "/txt1111.txt", $con->plaintext);
9 ?>

【问题讨论】:

  • $con 不是一个对象,它是一个字符串,将 $con-&gt;plaintext 更改为 $con
  • 也许 content1 和 context2 确实有一个明文方法,但是在连接它们时会隐式转换为字符串
  • 感谢@Dagon 的工作。但它包含html标签,你能告诉我如何过滤文本文件中的那些html标签吗?我是 php 新手。
  • 谢谢@ArtisticPhonix,现在我得到纯文本。

标签: php html parsing dom text


【解决方案1】:

很明显

$con=$content1.$content2;

这意味着 $con 是一个字符串,witch 不是一个对象。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多