Pyh.conf’25: a new PHP conference for the Russian-speaking community

Voting

: four minus zero?
(Example: nine)

The Note You're Voting On

Kari "Haprog" Sderholm
16 years ago
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);
}
?>

<< Back to user notes page

To Top