In reply to Dev_Engine:
Your use of strings is incorrect.
The function $fgetc() doesn’t return a string, it returns an integer type. You should get an incompatible assignment error when trying to assign the return of $fgetc() to a string type.
You likely want to use ‘int’ instead of ‘string’ throughout your code.