We have share in this tutorial how to Reading, Counting Line, Words, and Characters in File With PHP. First, read the file into a string with a function such as file_get_contents(). The numbers of words and characters can then be obtained by running the str_word_count() and strlen () function on the string.