Skip to content

Instantly share code, notes, and snippets.

@omitobi
Created November 7, 2017 12:56
Show Gist options
  • Select an option

  • Save omitobi/4960bf212c5286d727f299f4613eac55 to your computer and use it in GitHub Desktop.

Select an option

Save omitobi/4960bf212c5286d727f299f4613eac55 to your computer and use it in GitHub Desktop.
String pad
/**
* @param string $string
* @param string $pad
* @param int $expected_length
* @return string
*/
function str_pad($string, $pad, $expected_length)
{
$left = $expected_length - strlen($string);
while ($left > 0) {
$string = $pad.$string;
$left --;
}
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment