Skip to content

Instantly share code, notes, and snippets.

@nebiros
Created November 4, 2009 20:30
Show Gist options
  • Save nebiros/226350 to your computer and use it in GitHub Desktop.
Save nebiros/226350 to your computer and use it in GitHub Desktop.
mb_str_pad
<?php
/**
* mb_str_pad
*
* @param string $input
* @param int $pad_length
* @param string $pad_string
* @param int $pad_type
* @return string
* @author Kari "Haprog" Sderholm
*/
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 );
}
@Lewiscowles1986
Copy link

bad idea as unless the whole string is multi-byte this could lead to issues with string encoding...

@trialforce
Copy link

Works for me.

@ksidibe
Copy link

ksidibe commented Mar 13, 2017

Works for me too...
This is the behavior I expected from str_pad.

@rquadling
Copy link

@potenselyanin
Copy link

@rquadling
Copy link

@mrtnzagustin
Copy link

Thanks man. 2 hours with this problem.

@carloscarucce
Copy link

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment