[ Team LiB ] Previous Section Next Section


Strings are PHP's principal means of communication with the outside world and of storing information for later use. This hour has covered some of the functions that enable you to take control of the strings in your scripts.

You learned how to format strings with printf() and sprint(). You should be able to use these functions both to create strings that transform data and to lay it out. You learned about functions that investigate strings. You should now be able to discover the length of a string with strlen(), determine the presence of a substring with strpos(), and extract a substring with substr(). You should also be able to tokenize a string with strtok().

Finally, you learned about functions that transform strings. You can now remove white space from the beginning or end of a string with trim(), itrim(), and rtrim(). You can change case with strtoupper(), strtolower(), and ucwords(), and you can replace all instances of a string with str_replace().

Finally, you learned about two functions for formatting numbers:

number_format () and money_format ().

Believe it or not, you are not finished with strings yet. PHP supports regular expressions, which are an even more powerful means of working with strings than the functions already examined. We will look at these in detail in Hour 18, "Working with Regular Expressions."

    [ Team LiB ] Previous Section Next Section