note 49623 deleted from function.str-pad by danbrown
| From: | danbrown@php.net | Date: | Sat, 02 Jul 2011 18:56:19 +0000 |
| Subject: | note 49623 deleted from function.str-pad by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-181196@lists.php.net to get a copy of this message | ||
Note Submitter: Tomek Krzeminski
----
for those who want to pad strings in UTF-8 charset (for example)
(orig by bob)
---------------
private function iconv_str_pad( $input, $pad_length, $pad_string = '', $pad_type = 1,
$charset = "UTF-8" )
{
$str = '';
$length = $pad_length - iconv_strlen( $input, $charset );
if( $length > 0)
{
if( $pad_type == STR_PAD_RIGHT )
{
$str = $input . str_repeat( $pad_string, $length );
} elseif( $pad_type == STR_PAD_LEFT )
{
$str = str_repeat( $pad_string, $length ) . $input;
} elseif( $pad_type == STR_PAD_BOTH )
{
$str = str_repeat( $pad_string, floor( $length / 2 ));
$str .= $input;
$str .= str_repeat( $pad_string, ceil( $length / 2 ));
} else
{
$str = str_repeat( $pad_string, $length ) . $input;
}
} else
{
$str = $input;
}
return $str;
}