PHP fgets() ဘာသာစကား

အသုံးပြုခြင်း နှင့် လက်ဆုံးသတ္တိ

fgets() ဘာသာစကား ဖိုင်စာသင်္ချာမှ တစ်လျှောက်ဖတ်သင့်သည်။

ဘာသာစကား

fgets(file,length)
ပါဝင်သည် ဖော်ပြ
file တောင်းခိုင်းသည်။ ဖတ်သင့်သော ဖိုင်ကို အသုံးပြုပါ။
length အဆိုခဲ့သည်။ ဖတ်သင့်သော ဘာသာစကားလုံးပါးသည်။ ပုံစံ 1024 ဘာသာစကားလုံးဖြစ်သည်။

Description

from file Reads a line from the file pointed to and returns a length of up to length - 1-byte string. Encountered newline (including in the return value), EOF, or already read length - Stop after -1 byte (depending on which one comes first). If not specified lengthis set to 1K, or 1024 bytes.

If it fails, it returns false.

Tips and comments

Note:length The parameter has become optional from PHP 4.2.0. If ignored, the line length is assumed to be 1024 bytes. From PHP 4.3 onwards, it is ignored length It will continue to read data from the stream until the end of the line. If most of the lines in the file are greater than 8 KB, it is more effective to specify the maximum line length in the script in terms of resource usage.

Note:This function can be used safely with binary files from PHP 4.3 onwards. It does not work with earlier versions.

Note:If PHP cannot recognize the line endings of Macintosh files when reading files, you can enable the auto_detect_line_endings runtime configuration option.

Instance

Example 1

<?php
$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);
?>

Output similar to:

Hello, this is a test file.

Example 2

<?php
$file = fopen("test.txt","r");
while(! feof($file))
  {
  echo fgets($file). "<br />";
  }
fclose($file);
?>

Output similar to:

Hello, this is a test file. 
There are three lines here. 
This is the last line.