note 64260 deleted from function.str-pad by bjori
| From: | bjori@php.net | Date: | Tue, 11 Apr 2006 11:43:35 +0000 |
| Subject: | note 64260 deleted from function.str-pad by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-107765@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster at tmproductionz dot com
Reason: useless
----
<?php
// Syntax: remove_padding ( STR , INT , INT ) ;
// $var is the string passed
// $char is the character used for the padding, default is 0
// $c is for a case-sensitive search, default is 0 (case-insensitive)
function remove_padding ( $var , $char = 0 , $c = 0 ) {
$i = 0;
$l = strlen ( $var ) ;
$r = '';
if ( $l == 0 ) return "";
if ( $c == 0 ) {
if ( eregi ( $char . '{' . $l . '}' , $var ) ) return "";
} else {
if ( ereg ( $char . '{' . $l . '}' , $var ) ) return "";
}
while ( $i < $l ) {
if ( $c == 0 ) {
if ( strtolower ( $var{$i} ) != strtolower ( $char ) ) {
$r .= $var{$i} ;
$i = $l ;
}
} else {
if ( $var{$i} != $char ) {
$r .= $var{$i} ;
$i = $l ;
}
}
$i++;
}
return $r ;
}
?>
NOTE: This function will only work for the padding to the left of the passed string, and and
currently this function only works when the string is padded by one character, not a phrase
('0' and not '_0_').
eg.
<?php
$str = 000001234567890;
echo remove_padding($str); // outputs: '1234567890'
?>