【问题标题】:PHP fread reading the string '0'PHP fread 读取字符串'0'
【发布时间】:2012-05-28 15:43:28
【问题描述】:

你好,我使用 fread 来从 url 中获取整数:

$f = fopen("http://sometextfilecontaininganinteger.txt", "r");
$incoming = fread($f, 16);
fclose($f);
if ($incoming)
{

if 检查用于查看http 调用是否成功。 不幸的是,当文本文件包含字符串“0”时,这也会失败。 我该如何解决这个问题?

http://php.net/manual/en/function.fread.php

【问题讨论】:

标签: php fread


【解决方案1】:

检查是否为“Not identical

if ($incoming !== false) {
   // ...
}

【讨论】:

    【解决方案2】:

    代替

    if ($incoming)
    {
    

    你必须使用

    if ($incoming !== FALSE)
    {
    

    因为 '0' 在不比较类型时等于 FALSE。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-31
      • 2012-02-10
      • 2012-09-07
      • 2018-11-04
      • 1970-01-01
      • 2017-10-26
      • 2016-04-16
      相关资源
      最近更新 更多