See PHP Guide for Accessing and Modifying a String by Character
Characters in string s can be accessed and changed by specifying the zero offset of the desired character after the string using square brackets, as in $str[42] . Think of a string as an array of characters for this purpose. The substr() and substr_replace() functions can be used if you want to extract or replace more than 1 character.
Or, if you are after searching and reading bytes from a file, you can use SplFileObject
$file = new SplFileObject('file.txt'); while (false !== ($char = $file->fgetc())) { echo "$char\n"; }
This is not a byte array, but, but repeated over the file descriptor. SplFileInfo implements the SeekableIterator interface.
And on the sidebar there is also
- file - returns a file in an array. Each element of the array corresponds to a line in the file, and a new line is still attached. After the failure, the file () returns FALSE.
Gordon
source share