| |||||||||||
| |||||||||||
PHP - dividing a string up into pieces
"There's a function to do that ..." is the oft-used answer to many questions asked of PHP, but naturally that's followed by a plea of "what's it called". If you're looking to divide a string into a series or pieces, choose from these.
explode Returns an array, elements divided at a particular separator strtok Returns the next element (token) each time it's called. substr Returns a part of the incoming string based on position and length split Returns an a array of elements divided at a case sensitive POSIX regular expression spliti Returns an a array of elements divided at a case insensitive POSIX regular expression preg_split Returns an array of elements divided at a Perl style regular expression fgetcsv Reads a line from file and return it as an array. Input format is comma (or tab) separated variables, where delimiters can be included within quoted strings without causing an extra element to be generated. unpack Unpacks the data from a binary string into an associative array You can also use ereg, eregi and preg_match to match a string and return an array of interesting bits ... you could consider that to be yet another way to divide a string into pieces. (written 2006-01-23 02:20:36) Associated topics are indexed under H107 - String Handling in PHP
Some other Articles
Woman screaming at meLearning to program in Perl or PHP Why run two different web servers Eating for the single business traveller PHP - dividing a string up into pieces Giving an excuse for Christmas Giving the researcher power over database analysis Well House Manor Features and Benefits Instructions for bright people 1635 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 at 50 posts per pageThis is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price. Link to Ezine home page (for reading). Link to Blogging home page (to add comments). |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||