PX : code

Exploder class by Ed Williams
Download this code


<?php
/******************************************************************
class Exploder
******************************************************************* 

    Purpose : split a string up into segments given delimiter(s)    
    Usage : pizza = "slice1:slice2|slice3:|slice4";
            expl = new Exploder(array(":","|"), pizza); 
            slices = expl->GetSegments();
                        
*******************************************************************/

class Exploder {

    var 
$m_segments;
    
    function 
Exploder($tokens$string) {

        
$string stripslashes($string);            
        
$start true;
                
        for (
$i=0$i strlen($string); $i++) {
            
            
// check for token
            
for ($t=0$t count($tokens); $t++) {
                if (
$string[$i] == $tokens[$t]) {
                    if (
$start) {
                        
// save segment
                        
$this->m_segments[] = $segment;                     
                        unset(
$segment);
                    }           
                    
$start false;                     
                    break;
                }
            }
            
            
// check if token found                         
            
if ($t == count($tokens))
                
$start true;
            
            
// append character to segment          
            
if ($start)
                
$segment .= $string[$i];                                
        }
        if (
$start)
            
$this->m_segments[] = $segment;
    }       
    function 
GetSegments() {
        return 
$this->m_segments;
    }
    function 
GetNumber() {
        return 
count($this->m_segments);
    }   
};
?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.