fgetcsv_variation23.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --TEST--
  2. Test fgetcsv() : usage variations - empty file
  3. --FILE--
  4. <?php
  5. /*
  6. Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] );
  7. Description: Gets line from file pointer and parse for CSV fields
  8. */
  9. /* Testing fgetcsv() to read from an empty file */
  10. echo "*** Testing fgetcsv() : reading from file which is having zero content ***\n";
  11. // try reading from file which is having zero content
  12. // create the file and then open in read mode and try reading
  13. $filename = dirname(__FILE__) . '/fgetcsv_variation23.tmp';
  14. $fp = fopen ($filename, "w");
  15. fclose($fp);
  16. $fp = fopen ($filename, "r");
  17. if (!$fp) {
  18. echo "Error: failed to create file $filename!\n";
  19. exit();
  20. }
  21. var_dump( fgetcsv($fp) );
  22. var_dump( ftell($fp) );
  23. var_dump( fgetcsv($fp, 1024) );
  24. var_dump( ftell($fp) );
  25. var_dump( fgetcsv($fp, 1024, "+" ) );
  26. var_dump( ftell($fp) );
  27. var_dump( fgetcsv($fp, 1024, "+", "%") );
  28. var_dump( ftell($fp) );
  29. // close and delete the file
  30. fclose($fp);
  31. unlink($filename);
  32. echo "Done\n";
  33. ?>
  34. --EXPECT--
  35. *** Testing fgetcsv() : reading from file which is having zero content ***
  36. bool(false)
  37. int(0)
  38. bool(false)
  39. int(0)
  40. bool(false)
  41. int(0)
  42. bool(false)
  43. int(0)
  44. Done