Thread: Picky explode()
View Single Post
Old 06-15-2008, 11:06 PM   #5 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Not too sure about using preg_split but here's a possible regex solution:

PHP Code:
function regex_explode($string)
{
    
preg_match_all('/
        # Previous character is start of string or a comma
        (?<=^|,)
        #Followed by
        (?:
            # Zero or more non-curly brace characters between curly braces
            {[^{}]*}
            # or 
            |
            # Zero or more non-comma characters
            [^,]*
        )
    /x'
$string$matches);
    
    
// preg_match_all('/(?<=^|,)(?:{[^{}]*}|[^,]*)/', $string, $matches);
    
    
return current($matches);

Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
Tree (06-15-2008)