I'm drowning in PHP

Andy Armstrong andy at hexten.net
Tue May 15 04:12:31 BST 2007


This is a small gem from some PHP I'm obliged to look at:

   function strip_zero($str) {
     //Strips preceding zeros
     $new = "";
     $pre = 1;
     for($i=0; $i<strlen($str); $i++) {
       if($pre == 1) {
         if($str{$i} != "0") {
           $pre = 0;
           $new .= $str{$i};
         }
       } else {
         $new .= $str{$i};
       }
     }
     return $new;
   }

Either written by a C programmer or naively converted from C I'd say.
Bear in mind that PHP /does/ have regex support.

-- 
Andy Armstrong, hexten.net



More information about the london.pm mailing list