Advertisement
Guest User

Untitled

a guest
May 25th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. <?php
  2. file_put_contents("lab14src.txt", file_get_contents($_SERVER['SCRIPT_FILENAME']));
  3.  
  4. echo "File To Array:\n";
  5. print_r(preg_split("/[\s,]+/", file_get_contents("file1.txt")));
  6. echo "\n\n";
  7.  
  8. $file1 = file("file1.txt");
  9. $file2 = file("file2.txt");
  10. $file3 = file("file3.txt");
  11.  
  12. for ($i=0; $i<count($file1); $i++)
  13. echo trim($file1[$i])." <=> ".
  14. trim($file2[$i])." <=> ".
  15. trim($file3[$i])." \n";
  16. echo "\n\n";
  17.  
  18. echo "File1 ^ File2\n";
  19. print_r(array_intersect($file1, $file2));
  20. echo "\n";
  21.  
  22. echo "File1 without File1 ^ File2 rows:\n";
  23. print_r(array_diff($file1, array_intersect($file1, $file2)));
  24. echo "\n\n";
  25.  
  26. $syms1 = join(" ", $file1);
  27. $syms2 = join(" ", $file2);
  28.  
  29. echo "Symbols File2^File1:\n";
  30. $symbols = array_intersect(str_split($syms1), str_split($syms2));
  31. echo join(array_flip(array_flip($symbols)));
  32. echo "\n\n";
  33. ?>
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. File To Array:
  44. Array
  45. (
  46. [0] => Apple
  47. [1] => Bespin
  48. [2] => Doring
  49. [3] => Unix
  50. [4] => System
  51. [5] => Stuff
  52. [6] => Release
  53. [7] => Build
  54. [8] => Complete
  55. [9] =>
  56. )
  57.  
  58.  
  59. Apple Bespin Doring <=> Apple Bespin Doring <=> File3 Row1
  60. Unix System Stuff <=> Trinity Observer Pattern <=> File3 Row2
  61. Release Build Complete <=> Release Build Complete <=> File3 Row3
  62.  
  63.  
  64. File1 ^ File2
  65. Array
  66. (
  67. [0] => Apple Bespin Doring
  68.  
  69. [2] => Release Build Complete
  70.  
  71. )
  72.  
  73. File1 without File1 ^ File2 rows:
  74. Array
  75. (
  76. [1] => Unix System Stuff
  77.  
  78. )
  79.  
  80.  
  81. Symbols File2^File1:
  82. Aple BsinDorg
  83. ytmuRadC
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. Apple Bespin Doring
  97. Unix System Stuff
  98. Release Build Complete
  99.  
  100. Apple Bespin Doring
  101. Trinity Observer Pattern
  102. Release Build Complete
  103.  
  104. File3 Row1
  105. File3 Row2
  106. File3 Row3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement