The function you are looking for is str_pad .
http://php.net/manual/de/function.str-pad.php
$str = 'ABCDEFGHI'; $longstr = str_pad($str, 32);
The default string already contains spaces.
Since your maximum length should be 32, and str_pad will not take any action if the string is longer than 32 characters, you can shorten it with substr , and then:
http://de.php.net/manual/de/function.substr.php
$result = substr($longstr, 0, 32);
This again will take no action if your line has exactly 32 characters, so you always end up with a line with 32 characters in $result .
source share