Tagged: PHP Cookbook

PHP Cookbook: Parsing Comma-Separated Data

Problem You have data in comma-separated values (CSV) format—for example, a file exported from Excel or a database—and you want to extract the records and fields into a format you can manipulate in PHP....

PHP Cookbook: Controlling Case

Problem You need to capitalize, lowercase, or otherwise modify the case of letters in a string. For example, you want to capitalize the initial letters of names but lowercase the rest. Solution Use ucfirst(...

PHP Cookbook: Replacing Substrings

Problem You want to replace a substring with a different string. For example, you want to obscure all but the last four digits of a credit card number before printing it. Solution Use substr_replace(),...

PHP Cookbook: Extracting Substrings

Problem You want to extract part of a string, starting at a particular place in the string. For example, you want the first eight characters of a username entered into a form. Solution Use...