Mar 5, 2007 ... D_Base / PHP Programming Solutions / Vikram Vaswani ...... Here, the cleartext
password is encrypted with PHP's crypt() function and the.
Working with Strings IN THIS CHAPTER: 1.1 Controlling String Case 1.2 Checking for Empty String Values 1.3 Removing Characters from the Ends of a String 1.4 Removing Whitespace from Strings 1.5 Reversing Strings 1.6 Repeating Strings 1.7 Truncating Strings 1.8 Converting Between ASCII Characters and Codes 1.9 Splitting Strings into Smaller Chunks 1.10 Comparing Strings for Similarity 1.11 Parsing Comma-Separated Lists 1.12 Parsing URLs
1.13 Counting Words in a String 1.14 Spell-Checking Words in a String 1.15 Identifying Duplicate Words in a String 1.16 Searching Strings 1.17 Counting Matches in a String 1.18 Replacing Patterns in a String 1.19 Extracting Substrings 1.20 Extracting Sentences from a Paragraph 1.21 Generating String Checksums 1.22 Encrypting Strings (One-Way Encryption) 1.23 Encrypting Strings (Two-Way Encryption) 1.24 Generating Pronounceable Passwords 1.25 Generating Unpronounceable Passwords
f you’re like most novice PHP developers, you probably have only a passing acquaintance with PHP’s string functions. Sure, you know how to print output to a Web page, and you can probably split strings apart and glue them back together again. But there’s a lot more to PHP’s string toolkit than this: PHP has more than 175 string manipulation functions, and new ones are added on a regular basis. Ever wondered what they were all for? If you have, you’re going to be thrilled with the listings in this chapter. In addition to offering you a broad overview of PHP’s string manipulation capabilities, this chapter discusses many other tasks commonly associated with strings in PHP— removing unnecessary whitespace, finding and replacing string patterns, counting and extracting string segments, identifying duplicate words, encrypting text and generating string passwords. Along the way, you’ll find out a little more about those mysterious string functions, and also learn a few tricks to help you write more efficient code.
1.1 Controlling String Case Problem You want to force a string value to upper- or lowercase.
Solution Use the strtoupper() or strtolower() functions: