<?php
/**
* @version $Id$
* @package utf8
* @subpackage strings
*/
//---------------------------------------------------------------
/**
* Replacement for str_pad. $padStr may contain multi-byte characters.
*
* @author Oliver Saunders <oliver (a) osinternetservices.com>
* @param string $input
* @param int $length
* @param string $padStr
* @param int $type ( same constants as str_pad )
* @return string
* @see http://www.php.net/str_pad
* @see utf8_substr
* @package utf8
* @subpackage strings
*/
function utf8_str_pad($input, $length, $padStr = ' ', $type = STR_PAD_RIGHT) {
$inputLen = utf8_strlen($input);
if ($length <= $inputLen) {
return $input;
}
$padStrLen = utf8_strlen($padStr);
$padLen = $length - $inputLen;
if ($type == STR_PAD_RIGHT) {
$repeatTimes = ceil($padLen / $padStrLen);
return utf8_substr($input . str_repeat($padStr, $repeatTimes), 0, $length);
}
if ($type == STR_PAD_LEFT) {
$repeatTimes = ceil($padLen / $padStrLen);
return utf8_substr(str_repeat($padStr, $repeatTimes), 0, floor($padLen)) . $input;
}
if ($type == STR_PAD_BOTH) {
$padLen/= 2;
$padAmountLeft = floor($padLen);
$padAmountRight = ceil($padLen);
$repeatTimesLeft = ceil($padAmountLeft / $padStrLen);
$repeatTimesRight = ceil($padAmountRight / $padStrLen);
$paddingLeft = utf8_substr(str_repeat($padStr, $repeatTimesLeft), 0, $padAmountLeft);
$paddingRight = utf8_substr(str_repeat($padStr, $repeatTimesRight), 0, $padAmountLeft);
return $paddingLeft . $input . $paddingRight;
}
trigger_error('utf8_str_pad: Unknown padding type (' . $type . ')',E_USER_ERROR);
}
| nama | waktu | ukuran | owner | perm | aksi |
|---|---|---|---|---|---|
| .. | |||||
| mbstring/ | 2013-02-26 20:16 | 4.13 KB | 76129f60960:kunden | dxwrx-rx-r | |
| native/ | 2013-02-26 20:16 | 16.63 KB | 76129f60960:kunden | dxwrx-rx-r | |
| utils/ | 2013-02-26 20:16 | 52.66 KB | 76129f60960:kunden | dxwrx-rx-r | |
| LICENSE | 2013-02-26 20:15 | 25.81 KB | 76129f60960:kunden | -xw-x----- | |
| README | 2013-02-26 20:15 | 3.29 KB | 76129f60960:kunden | -xw-x----- | |
| index.html | 2013-02-26 20:15 | 31 B | 76129f60960:kunden | -xw-x----- | |
| ord.php | 2013-02-26 20:15 | 2.35 KB | 76129f60960:kunden | -xw-x----- | |
| str_ireplace.php | 2013-02-26 20:15 | 1.95 KB | 76129f60960:kunden | -xw-x----- | |
| str_pad.php | 2013-02-26 20:15 | 1.67 KB | 76129f60960:kunden | -xw-x----- | |
| str_split.php | 2013-02-26 20:15 | 824 B | 76129f60960:kunden | -xw-x----- | |
| strcasecmp.php | 2013-02-26 20:15 | 546 B | 76129f60960:kunden | -xw-x----- | |
| strcspn.php | 2013-02-26 20:15 | 894 B | 76129f60960:kunden | -xw-x----- | |
| stristr.php | 2013-02-26 20:15 | 855 B | 76129f60960:kunden | -xw-x----- | |
| strrev.php | 2013-02-26 20:15 | 458 B | 76129f60960:kunden | -xw-x----- | |
| strspn.php | 2013-02-26 20:15 | 923 B | 76129f60960:kunden | -xw-x----- | |
| substr_replace.php | 2013-02-26 20:15 | 600 B | 76129f60960:kunden | -xw-x----- | |
| trim.php | 2013-02-26 20:15 | 2.18 KB | 76129f60960:kunden | -xw-x----- | |
| ucfirst.php | 2013-02-26 20:15 | 787 B | 76129f60960:kunden | -xw-x----- | |
| ucwords.php | 2013-02-26 20:15 | 1.44 KB | 76129f60960:kunden | -xw-x----- | |
| utf8.php | 2013-02-26 20:15 | 2.22 KB | 76129f60960:kunden | -xw-x----- | |