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

20 lines
823 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
$filename = "data/07.txt";
$total = filesize($filename);
if (is_file($filename)) {
echo "文件总字节数:" . $total . "<br>";
$fopen = fopen($filename, 'rb');
echo "初始指针位置是:" . ftell($fopen) . "<br>";
fseek($fopen, 30);
// 07.txt原先是UTF-8 with BOM编码现在已经转换为UTF-8编码故不需要33
echo "使用fseek()函数后指针位置:" . ftell($fopen) . "<br>";
echo "输出当前指针后面的内容:" . fgets($fopen) . "<br>";
if (feof($fopen))
echo "当前指针指向文件末尾:" . ftell($fopen) . "<br>";
rewind($fopen);
echo "使用rewind()函数后指针的位置:" . ftell($fopen) . "<br>";
echo "输出前31字节的内容" . fgets($fopen, 31);
fclose($fopen);
} else {
echo "文件不存在";
}