Is there a better way of doing this?

From: Date: Wed, 21 Aug 2002 19:40:37 +0000
Subject: Is there a better way of doing this?
Groups: php.general 
Request: Send a blank email to php-general+get-113521@lists.php.net to get a copy of this message
Hello all, You have been lots of help in the past, so I was wondering if you could help me out with this, basically I just have to parse a string similar to "4,31m)" figure out if it is numeric or not, then if it is remove the last to characters on the string (the 'm)') and change the string so that it is 4.31. There is probably a better way of doing this but I can't figure out how to make it better or more efficient $tim = "3,43m)"; // take into account that the last 2 characters may not be\ 'm)' like we are expecting, and store them in a var $last2ontime = substr($tim,strlen($tim),strlen($tim)-3); $tim = str_replace(",","",$tim); // get rid of the , in the time (i.e. time = 3,43 and we want it to be 343) $tim = substr($tim,0,strlen($tim)-2); if(is_numeric($tim)){ if($debug){ print nl2br( "Time is Numeric!\n" ); } $t = substr($tim,0,strlen($tim)-2); $te = substr($tim,strlen($tim)-2); if($debug){ print nl2br( "T = $t\nte = $te\n" ); } if(is_null($t) or $t == ""){ $tim = $te[0] .".0". $te[1]; }else{ $tim = (string)$t .".". (string)$te ."m)"; } }else{ if($debug){ print "got else!"; } Thank You, Mike funyon@funyon.com mmacrae@wwnet.net

« previous php.general (#113521) next »