PHP | SplFileObject fgetc() Function
The SplFileObject::fgetc() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to get character from file.
Syntax:
string SplFileObject::fgetc( void )
Parameters: This function does not accept any parameter.
Return values: Returns single character read from the file or FALSE on EOF.
Below Programs illustrate the SplFileObject::fgetc() function in PHP.
Note: Program 1 has used gfg.txt file that contains following data.
GeeksforGeeks
Program 1: Print All characters of file by one space separated.
<?php // Create SplFileObject object $file = new SplFileObject("gfg.txt"); // Print all characters of file while (false !== ($gfg = $file->fgetc())) { echo "$gfg"; } ?> |
Output:
G e e k s f o r G e e k s
Program 2: Print all characters of current file.
<?php // Create SplFileObject object $file = new SplFileObject(__FILE__); // Print all characters of file while (false !== ($gfg = $file->fgetc())) { echo "$gfg"; } ?> |
<?php
// Create SplFileObject object
$file = new SplFileObject(__FILE__);
// Print all characters of file
while (false !== ($gfg = $file->fgetc()))
{
echo "$gfg";
}
?>
Reference: http://php.net/manual/en/splfileobject.fgetc.php
Recommended Posts:
- PHP | fgetc( ) Function
- PHP | SplFileObject eof() Function
- PHP | SplFileObject rewind() Function
- PHP | SplFileObject ftruncate() Function
- PHP | SplFileObject current( ) Function
- PHP | SplFileObject seek() Function
- PHP | SplFileObject fgets() Function
- PHP | SplFileObject fgetss() Function
- PHP | SplFileObject fread() Function
- PHP | SplFileObject fwrite() Function
- PHP | SplFileObject getMaxLineLen() Function
- PHP | SplFileObject flock() Function
- PHP | SplFileObject setMaxLineLen() Function
- PHP | SplFileObject ftell() Function
- PHP | SplFileObject fputcsv() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



