1
0
Fork 0
php-coding/13.test1.php

59 lines
1.1 KiB
PHP

<?php
$readfile = readfile('data/read_test_file');
if (!$readfile)
echo '文件读取失败';
echo '<br>';
$file_array = file('data/read_test_file');
if (!$file_array) {
echo '文件读取失败';
return;
}
foreach ($file_array as $item)
echo $item . '<br>';
echo '<br>';
$file_get_contents = file_get_contents('data/read_test_file');
if ($file_get_contents === false) {
echo '文件读取失败';
return;
}
echo $file_get_contents;
echo '<br>';
$resource = fopen('data/fun.php', 'rb');
while (!feof($resource)) {
echo fgets($resource);
}
rewind($resource);
echo '<br>';
while (!feof($resource)) {
// echo fgetss($resource,,) // fgetss function is removed in php8
// echo strip_tags(fgets($resource));
echo htmlspecialchars(fgets($resource), ENT_QUOTES, 'UTF-8');
}
fclose($resource);
echo '<br>';
$resource1 = fopen('data/read_test_file', 'rb');
while (($char = fgetc($resource1)) !== false) {
echo $char;
}
rewind($resource1);
echo '<br>';
echo fread($resource1,30).'<br>'; //中文占3字节
echo fread($resource1,filesize('data/read_test_file'));
fclose($resource1);
echo '<br>';