note 52983 deleted from function.str-pad by danbrown
| From: | danbrown@php.net | Date: | Sat, 02 Jul 2011 18:56:08 +0000 |
| Subject: | note 52983 deleted from function.str-pad by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-181195@lists.php.net to get a copy of this message | ||
Note Submitter: Anloc <info NOSPAM at anloc dot net>
----
Tomek Krzeminski's iconv_str_pad modified for php 4 (iconv_strlen only works for php 5)
courtesy of www.anloc.net
function iconv_str_pad( $input, $pad_length, $pad_string = '', $pad_type = 1, $charset
= "UTF-8" )
{
$str = '';
// $length = $pad_length - iconv_strlen( $input, $charset );
$length = $pad_length - preg_match_all('/./u', $input, $dummy);
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;
}