Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check That Certain Characters Exist in a File

Status
Not open for further replies.

likelylad

IS-IT--Management
Joined
Jul 4, 2002
Messages
388
Location
GB
Hopefully someone can me with this one.

I have text files that need to be read and checked to see if they contained particular pre-defined characters.

All I can do at the moment is open the text file and output it to a page.

What I would like to do is read the text file one character at a time and compare it against my list of pre-defined characters and then output how many pre-defined characters it found.

Can anyone set me off in the right direction as to what the best functions would be to use

Thanking in advance for any help received.

 
the amount of data in the text file would say how i would do this, how big is the file?

To err is human, to completely mess up takes a computer. [morning]
 
How about all the file functions --

fgetc()
fscanf()
fgets()
fread()
etc...



Rocco is the BOY!!

SHUT YOUR LIPS...
ROCCOsm.gif
 
thanks everyone for pointing me in the right direction
 
More Help Please

At the moment I can
I can read the contents of a file.
I am spliting the file contents at the new line character.
How do I loop through each line.
I know I should be using a do...while but I don't know how to close the loop

This is my code so far


$filename = 'c:\test.txt';
$fp = fopen($filename, "r");
$contents = fread($fp, filesize($filename));
fclose($fp);

$splitfile=preg_split("/[\n]/",$contents);

echo $splitfile[0];


 
I have found a solution to this one

I am using the count function to count the number of elements in the array so that I know how many time I have to loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top