【问题标题】:Notice: Trying to get property of non-object in C:\xampp\htdocs\fps.php on line 117注意:尝试在第 117 行的 C:\xampp\htdocs\fps.php 中获取非对象的属性
【发布时间】:2013-10-12 00:47:36
【问题描述】:

您好,我已经在这里和其他网站上广泛研究了这个问题,但没有找到我的答案。首先让我先说我正在尝试自己学习这一切,因此欢迎任何建议。

我正在尝试 curl 托管我们的一个应用程序的网站。我试图将它的内容转储到一个销售演示的 div 中,但我很难这样做。由于它是 Https 协议,因此简单的 iFrame 将无法完成这项工作。同样,这是我们公司拥有的应用程序,但托管在社交网站上。

这是我的头部代码:

<?php
    // Defining the basic cURL function
    function file_get_html($url) {
    $ch = curl_init();  // Initialising cURL
    curl_setopt($ch, CURLOPT_URL, "https://www.a_website.com");
    curl_setopt($ch, CURLOPT_URL, 1);
    curl_setopt($ch, CURLOPT_URL, $url);    // Setting cURL's URL option with the $url variable passed into the function
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Setting cURL's option to return the webpage data
    $data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
    // var_dump($data);
    curl_close($ch); // Closing cURL
    return $data;   // Returning the data from the function
    }
  ?>

我已经尝试过 var_dump($data) 建议,我将其视为类似帖子(例如我的帖子)的答案,但我是新手,不明白它的实际作用。我在这里和其他地方阅读其他帖子时知道“注意:尝试在第 117 行获取 C:\xampp\htdocs\fps.php 中非对象的属性”不是错误,而是警告/通知。

任何指导将不胜感激。

尝试将内容输出到:

<div>
  <?php
    // Dump contents (without tags) from HTML
    echo file_get_html("www.facebook.com/appcenter/sgprivacy")->html;
  ?>
</div>

任何指导将不胜感激。

【问题讨论】:

  • $data 是一个字符串,而不是一个对象。取下-&gt;html 就可以了。
  • 第 117 行是哪一行?使用 var_dump 得到了什么?

标签: php html curl


【解决方案1】:

这里有错误是准确的问题:

<div>
  <?php
    // Dump contents (without tags) from HTML
    echo file_get_html("www.facebook.com/appcenter/sgprivacy")->html; // this here
  ?>
</div>

file_get_html 返回的值不是对象,而是字符串。改成这样:

echo file_get_html("www.facebook.com/appcenter/sgprivacy");

如果要删除所有html标签,可以使用strip_tags()函数。

$data = file_get_html("www.facebook.com/appcenter/sgprivacy");
echo strip_tags($data);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    • 2019-07-31
    • 2017-08-24
    • 2018-03-22
    • 2019-02-24
    相关资源
    最近更新 更多