note 89754 added to function.str-pad
| From: | Kari" | Date: | Sat, 21 Mar 2009 14:43:14 +0000 |
| Subject: | note 89754 added to function.str-pad | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152263@lists.php.net to get a copy of this message | ||
Here's a quick and simple way to make an mb_str_pad function that works when you have correctly
set your internal encoding.
I'm not sure how well this works in all possible scenarios but atleast it worked for me using
UTF-8 as internal encoding and using this function on strings containing scandinavian characters
"åäöÃ
ÃÃ" that are double byte in UTF-8.
<?php
function mb_str_pad($input, $pad_length, $pad_string=' ', $pad_type=STR_PAD_RIGHT) {
$diff = strlen($input) - mb_strlen($input);
return str_pad($input, $pad_length+$diff, $pad_string, $pad_type);
}
?>
----
Server IP: 62.237.7.3
Probable Submitter: 80.220.62.122
----
Manual Page -- http://www.php.net/manual/en/function.str-pad.php
Edit -- https://master.php.net/note/edit/89754
Del: integrated -- https://master.php.net/note/delete/89754/integrated
Del: useless -- https://master.php.net/note/delete/89754/useless
Del: bad code -- https://master.php.net/note/delete/89754/bad+code
Del: spam -- https://master.php.net/note/delete/89754/spam
Del: non-english -- https://master.php.net/note/delete/89754/non-english
Del: in docs -- https://master.php.net/note/delete/89754/in+docs
Del: other reasons-- https://master.php.net/note/delete/89754
Reject -- https://master.php.net/note/reject/89754
Search -- https://master.php.net/manage/user-notes.php