![]() ![]() ![]() Since in any case I had to split up the numeric triplets afterwards, I decided to use preg_match_all() on the original string. The workaround was easy and had the bonus of producing faster code (I compared it on a 10000 triplet string). ![]() I'm expecting to get an array of 20000 strings, but it needs more than 32MB to store it. Well, PHP5 manages to run out of memory *at the first stage* (exploding the string on the space character). And I expect some overhead from PHP, say 300% to allow for indexes etc. The intermediate array of strings shouldn't be much bigger than the long string itself (1MB). In C, this would take up about 480K (20000 times 3 x 8 bytes) for the final array. The application needs to split the string into triplets, then split the triplet into numbers. Total size of the biggest string, with 20000 triplets, is about 1MB. I have a string containing between 10 triplets, separated by a space, with each triplet consisting of three double-precision numbers, separated by commas. My application was running out of memory (my hosting company limits PHP to 32MB). One way to avoid getting back empty parts (if you don't care for those empty parts) is to use array_filter on the result. The boundary splits the string into two parts even though those parts are empty. The reason we have two empty strings here is that a boundary is discovered before any data has been collected from the string. Whether or not that boundary is proceeded or superseded by any data is irrelevant since the parts are determined at the point a boundary is discovered. Once that boundary is discovered the string is split. Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Errors Exceptions Generators References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Filesystem Security Database Security Error Reporting Using Register Globals User Submitted Data Magic Quotes Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Safe Mode Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Credit Card Processing Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation Keyboard Shortcuts ? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto searchĮxplode does not parse a string by delimiters, in the sense that we expect to find tokens between a starting and ending delimiter, but instead splits a string into parts by using a string as the boundary of each part. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |