【问题标题】:how to disable warning message and instead show the other message in php? [duplicate]如何禁用警告消息,而是在 php 中显示其他消息? [复制]
【发布时间】:2013-05-14 16:41:35
【问题描述】:
<?php
$html_url = 'http://api.biblia.com/v1/bible/content/LEB.html?passage=John333&style=fullyFormatted&key=fd37d8';
$str_html  = file_get_contents($html_url);

问题:

它显示:警告:file_get_contents(http://api.biblia.com/v1...

有没有办法可以隐藏这条消息,而不是显示一条消息,例如“无法显示结果”?

【问题讨论】:

  • 大多数情况下 file_get_contents( 在远程服务器上被禁用。您应该使用 PHP Curl 从 url 获取 html 内容

标签: php


【解决方案1】:
error_reporting(0);

试试this link

【讨论】:

    【解决方案2】:

    像这样使用@符号:

    $html_url = 'http://api.biblia.com/v1/bible/content/LEB.html?passage=John333&style=fullyFormatted&key=fd37d8';
    $str_html  = @file_get_contents($html_url);
    

    【讨论】:

      【解决方案3】:

      使用@ 来抑制警告。但它不是抑制警告/通知/错误的更可取的方法,相反,您应该尝试调试代码以检查幕后出现的问题。

      error_reporting() 是处理这些错误的另一种方式。

      【讨论】:

      • 那么哪个更可取?
      • 我后来的评论更清楚地说明了当前上下文中优选的含义
      猜你喜欢
      • 2012-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-31
      • 1970-01-01
      相关资源
      最近更新 更多