sunslayer commented on a Page, PHPTok  -  Dec 06, 2009

using RJosh's example i got this

    function gettok($string,$n,$c) {
      if(is_numeric($c)) $c=chr($c);
      $tok=explode($c,$string);
      if($n==0) return count($tok);
      elseif($n<0) {
         $tok=array_reverse($tok);
         return $tok[lasttok($n+1,"-")];
      }
      elseif(preg_match("/(\d+)-(\d+)?/",$n,$range)) {
        $start=$range[1]-1;
        if (!$range[2]) $end=numtok($string,$c);
        else $end=$range[2];
        for(;$start<$end;$start++,$text.=$tok[$start-1].$c);
        return $text;
      }
      else return $tok[$n-1];
    }

supports negative and multiple ranges

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.