Advertisement
Guest User

File

a guest
Nov 28th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="utf-8">
  5.     <title>File</title>
  6.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.css">
  7. </head>
  8. <body>
  9. <div class="container" align="center">
  10. <?php
  11. //Первый вариант считывания файла целиком
  12. $fp = fopen($name="php.txt", "rt") or die("Error!");
  13. $lines = explode("\n", fread($fp, filesize($name)));
  14. var_dump($lines);
  15. $strLines = '';
  16. foreach($lines as $key => $value){
  17.    $strLines .= $lines[$key];
  18. }
  19. echo $strLines;
  20. fclose($fp);
  21.  
  22. //Второй вариант считывания файла целиком
  23. $str = file_get_contents('php.txt');
  24. echo '<hr>'.$str.'<hr>';
  25.  
  26. //Третий вариант считывания файла блочно
  27. $fp = fopen($name="php.txt", "rb") or die("Error!");
  28. $strRead = '';
  29. while(!feof($fp)){
  30.     $strRead .= fread($fp, 100);
  31. }
  32. echo $strRead;
  33.  
  34. fclose($fp);
  35.  
  36. ?>
  37. </div>
  38. </body>
  39. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement