PageRenderTime 25ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/file/file_variation.php

https://github.com/tstarling/hiphop-php
PHP | 61 lines | 48 code | 7 blank | 6 comment | 1 complexity | 4502df56fc65a62f81cfb5cec64d2f62 MD5 | raw file
  1. <?php
  2. /*
  3. * Prototype: array file ( string filename [,int use-include_path [,resource context]] );
  4. * Description: Reads entire file into an array
  5. Returns the file in an array
  6. */
  7. require(dirname(__FILE__) . '/file.inc');
  8. $data_array = array( "Garbage data", "Gar\nba\nge d\nata", "Gar\n\nbage \n\n data" );
  9. echo "*** Using various flags values with different data in a file\n";
  10. $count=1;
  11. $file_path = dirname(__FILE__);
  12. foreach( $data_array as $data ) {
  13. echo "--Iteration $count --\n";
  14. $fh = fopen($file_path."/file_variation.tmp", "w");
  15. fwrite($fh, (binary)$data);
  16. var_dump( file($file_path."/file_variation.tmp", FILE_IGNORE_NEW_LINES) );
  17. var_dump( file($file_path."/file_variation.tmp", FILE_SKIP_EMPTY_LINES) );
  18. $count++;
  19. fclose($fh);
  20. }
  21. echo "*** Testing with variation in use_include_path argument ***\n";
  22. $file_path1 = dirname(__FILE__)."/file_variation";
  23. mkdir($file_path1);
  24. ini_set( 'include_path',$file_path.'/file_variation' );
  25. file_put_contents( $file_path1."/file1_variation.tmp", "aaaaaaaaaaaaaaabbbbbbbbbbb111111111222222222" );
  26. var_dump( file("file1_variation.tmp", FILE_USE_INCLUDE_PATH) );
  27. var_dump( file($file_path1."/file1_variation.tmp", 1) );
  28. echo "*** Using file function to remove line containing a key string ***\n";
  29. $file_handle = fopen($file_path."/file2_variation.tmp", "w");
  30. $key = "SEARCH_KEY";
  31. fwrite( $file_handle, (binary)"The key string to be searched is SEARCH_KEY\nLine without key string\nThe key string to be searched is SEARCH_KEY" );
  32. $out_array = file($file_path."/file2_variation.tmp");
  33. echo "File contents in array form Before replacement of the key\n";
  34. var_dump( $out_array );
  35. $file_handle2 = fopen($file_path."/file3_variation.tmp", "w");
  36. // Loop through file content array
  37. foreach($out_array as $line) {
  38. if( !strstr( $line, $key ) )
  39. fputs($file_handle2,$line);
  40. }
  41. echo "File contents in array form After replacement of the key\n";
  42. var_dump( file($file_path."/file3_variation.tmp" ));
  43. fclose($file_handle);
  44. fclose($file_handle2);
  45. echo "\n--- Done ---";
  46. ?>
  47. <?php
  48. $file_path = dirname(__FILE__);
  49. unlink($file_path."/file_variation.tmp");
  50. unlink($file_path."/file_variation/file1_variation.tmp");
  51. unlink($file_path."/file2_variation.tmp");
  52. unlink($file_path."/file3_variation.tmp");
  53. rmdir($file_path."/file_variation");
  54. ?>