Function in PHP

From: Date: Mon, 08 May 2000 13:08:15 +0000
Subject: Function in PHP
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-481@lists.php.net to get a copy of this message
Dear Webmaster (Developers), ...I think a function like this can be usefull (e.g. for leading zeros). Perhaps you can integrate it in your next release. Bye... Martin // Returns String "$str", filled with "$char"... function strfill($str, $char, $lenght){ // $str = Sting that should be taken // $char = Character to fill string (in front if $lenght is positive, else behind if $lenght is negative) // $lenght = Lenght of string // If absolute value of lenght is lower than lenght of string, return false if(abs($lenght)<strlen($str)){ return(FALSE); // If $str is as long as $lenght, return $str } else if(abs($lenght)==strlen($str)){ return($str); // Else, create String with $char } else { for($i=0; $i<=(abs($lenght)-strlen($str)); $i++){ $char_str=$char_str.$char; } // If absolute value of lenght is negative, fill behind string if($lenght<=0){ return($str.$char_str); // Else, fill in front... } else { return($char_str.$str); } } }

« previous php.mirrors (#481) next »