Break a string into parts, returning all characters

Posted by Benjamin on Stack Overflow See other posts from Stack Overflow or by Benjamin
Published on 2011-06-27T12:05:24Z Indexed on 2011/06/27 16:23 UTC
Read the original article Hit count: 214

Filed under:
|
|
|
|

I want to break a string according to the following rules:

  1. all consecutive alpha-numeric chars, plus the dot (.) must be treated as one part
  2. all other consecutive chars must be treated as one part
  3. consecutive combinations of 1 and 2 must be treated as different parts
  4. no whitespace must be returned

For example this string:

Method(hierarchy.of.properties) = ?

Should return this array:

Array
(
    [0] => Method
    [1] => (
    [2] => hierarchy.of.properties
    [3] => )
    [4] => =
    [5] => ?
)

I was unsuccessful with preg_split(), as AFAIK it cannot treat the pattern as an element to be returned.

Any idea for a simple way to do this?

© Stack Overflow or respective owner

Related posts about php

Related posts about php5