Skip to content

Instantly share code, notes, and snippets.

@nhalstead
Created March 5, 2018 01:36
Show Gist options
  • Save nhalstead/0e6462af816861b9a7be5f542a96abf3 to your computer and use it in GitHub Desktop.
Save nhalstead/0e6462af816861b9a7be5f542a96abf3 to your computer and use it in GitHub Desktop.
Fit Text
<?php
/**
* Fill the Gaps, Fit Text to a Length.
*
* @param Int Input of the Target Length
* @param String The Text to Extend with $char
* @param String The Char to use to fill the blanks.
*/
function fitText($textLength, $text, $char = " "){
$t = strlen($text);
$fillC = $textLength - $t;
$fill = str_repeat($char, $fillC);
return $text.$fill;
}
header('Content-Type: text/plain');
echo "`".fitText(15, "192.168.1.1")."`";
echo "\n";
echo "`".fitText(15, "192.168.1.88")."`";
echo "\n";
echo "`".fitText(15, "192.168.1.255")."`";
echo "\n";
echo "`".fitText(15, "192.168.12.12")."`";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment