Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Read One Character from a File
How To Read One Character from a File? - PHP Script Tips - Reading and Writing Files
✍: FYIcenter.com
If you have a text file, and you want to read the file one character at a time, you can use the fgetc() function. It reads the current character, moves the file pointer to the next character, and returns the character as a string. If end of the file is reached, fgetc() returns Boolean false. Here is a PHP script example on how to use fgetc():
<?php
$file = fopen("/windows/system32/drivers/etc/services", "r");
$count = 0;
while ( ($char=fgetc($file)) !== false ) {
if ($char=="/") $count++;
}
fclose($file);
print("Number of /: $count\n");
?>
This script will print:
Number of /: 113
Note that rtrim() is used to remove "\n" from the returning string of fgets().
2007-04-22, 5227👍, 0💬
Popular Posts:
What is Concern in AOP? gA concern is a particular goal, concept, or area of interesth There are m...
What are the different storage classes in C? C has three types of storage: automatic, static and all...
What print out will the folloging code produce? main() { char *p1=“name”; char *p2; p2=(char*)malloc...
What will be printed as the result of the operation below: main() { int x=20,y=35; x=y++ + x++; y= +...
What is XSLT? XSLT is a rule based language used to transform XML documents in to other file formats...