Skip to content

Instantly share code, notes, and snippets.

@DAVIDhaker
Created March 19, 2020 12:10
Show Gist options
  • Save DAVIDhaker/04efb6abdcba85b6be234dd147d718ba to your computer and use it in GitHub Desktop.
Save DAVIDhaker/04efb6abdcba85b6be234dd147d718ba to your computer and use it in GitHub Desktop.
Pad unicode string right (like Python str.ljust)
<?php
function ljust($str, $len, $fill_char) {
$str_len = mb_strlen($str);
$out = range(0, max($str_len, $len));
$out_len = count($out);
for ($i = 0; $i < $out_len; $i++)
$out[$i] = $i < $str_len ? mb_substr($str, $i, 1) : $fill_char;
return implode("", $out);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment