View Single Post
  #4  
Old 01-09-2010, 06:46 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
I have an update... a year later. There is something wrong with the explode() function currently in the first post. I can't remember exactly what it is, but the output is incorrect for certain situations. The following version should fix those problems:

PHP Code:
public function explode(delimiterstringlimit) {
  
temp.tokens temp.string.tokenize(temp.delimiter);
  if(!
temp.delimiter || temp.delimiter == "") {
    return 
false;
  }
  if(!
temp.limit || temp.limit == 0) {
    return 
temp.string.tokenize(temp.delimiter);
  }
  if(
temp.limit temp.tokens.size()) {
    
temp.limit temp.tokens.size();
  }
  
  if(
temp.limit 0) {
    for(
temp.0temp.<= temp.limit 1temp.++) {
      
temp.output.add(temp.tokens[temp.i]);
    }
    for(
temp.0temp.temp.tokens.size() - temp.limittemp.++) {
      
temp.output[temp.limit 1] @= temp.delimiter temp.tokens[temp.limit temp.i];
    }
  }
  else {
    
temp.limit *= -1;
    for(
temp.0temp.<= temp.limit 1temp.++) {
      
temp.output.add(temp.tokens[temp.i]);
    }
  }
  return 
temp.output;

__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote