Iterating UTF-8 Strings
Learn about the UTF-8 string iterator implementation.
We'll cover the following...
We'll cover the following...
Throughout the rest of this chapter, we will work to implement the following class that we can use to iterate UTF-8 strings:
After our implementation is complete, the above will produce the following output:
Adding methods to an empty class
We will use all the techniques we’ve discussed so far, with the significant difference being the implementation details of various PHP interfaces. We will start with the following empty class and work to fill in all of the methods:
Our class accepts a string as part of its constructor and stores it internally. All of the class’s empty methods come from PHP’s Iterator interface, which allows us to create class implementations that we can use for each loop. We have also included the ...