note 84899 added to function.str-pad
| From: | sonysuwanamiharja at osu1 dot php dot net | Date: | Tue, 05 Aug 2008 08:38:12 +0000 |
| Subject: | note 84899 added to function.str-pad | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143152@lists.php.net to get a copy of this message | ||
// @function : str_pad_clear()
// @email : sonsonz@gmail.com
$string = "00001010"; // get 1010
$str = str_pad_clear($string,"0",STR_PAD_LEFT); // result 1010
echo $str;
function str_pad_clear($string, $char, $type = STR_PAD_LEFT) {
$strlen = strlen($string);
$pos = 0;
for ($x=0;$x<$strlen;$x++) {
if ($type == 'STR_PAD_LEFT') {
if (round(strpos($string,$char,$x),0) != round($x,0)) {
if ($pos == 0) {
$pos = $x;
continue;
}
}
} else {
//'STR_PAD_RIGHT'
if (strpos($string,$char,($x * -1)) != $x) {
if ($pos == 0) {
$pos = $x;
continue;
}
}
}
}
$str = substr($string,$pos);
return $str;
}
----
Server IP: 203.142.84.218
Probable Submitter: 210.79.210.214
----
Manual Page -- http://www.php.net/manual/en/function.str-pad.php
Edit -- https://master.php.net/note/edit/84899
Del: integrated -- https://master.php.net/note/delete/84899/integrated
Del: useless -- https://master.php.net/note/delete/84899/useless
Del: bad code -- https://master.php.net/note/delete/84899/bad+code
Del: spam -- https://master.php.net/note/delete/84899/spam
Del: non-english -- https://master.php.net/note/delete/84899/non-english
Del: in docs -- https://master.php.net/note/delete/84899/in+docs
Del: other reasons-- https://master.php.net/note/delete/84899
Reject -- https://master.php.net/note/reject/84899
Search -- https://master.php.net/manage/user-notes.php