0

hello i use fread like this to get an integer from an url:

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

the if check is there to see if the http call was successful. unfortunately this fails also when the textfile contains the string '0'. how could i work around this?

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

clamp
  • 33,000
  • 75
  • 203
  • 299
  • also check http://php.net/manual/en/function.fread.php for other methods for reading remote files. – sdjuan May 28 '12 at 15:52

2 Answers2

2

Check if it is "Not identical"

if ($incoming !== false) {
   // ...
}
fredley
  • 32,953
  • 42
  • 145
  • 236
Hampus Brynolf
  • 1,296
  • 11
  • 20
1

Instead of

if ($incoming)
{

you have to use

if ($incoming !== FALSE)
{

Because '0' equals to FALSE when not comparing the type.