PHP str_pad of populates a string with a specified length

  • 2020-03-31 20:25:33
  • OfStack



// string str_pad(string $str, int $len, string $pad_str, string $pad_type);

echo str_pad($result2[0],6,"0",STR_PAD_LEFT);

<?php 
$input = "Alien"; 
echo str_pad($input, 10); // produces "Alien " 
echo str_pad($input, 10, "-=", STR_PAD_LEFT); // produces "-=-=-Alien" 
echo str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___" 
echo str_pad($input, 6 , "___"); // produces "Alien_" 
?>

Related articles: