I've tried both
str_pad and str_repeat to insert blank spaces into a value.
I want the string to be 34 characters long. I can do it using any other character than a blank space.
Inserting a blank space truncates the value to 1 blank space.
I have even tried inserting another character, then replacing that character with a blank and I still get the truncation.
When I do a test on the string length,it returns the correct result, but the output does not show the blanks in the string.
the code below demonstrates the problem.
str_pad and str_repeat to insert blank spaces into a value.
I want the string to be 34 characters long. I can do it using any other character than a blank space.
Inserting a blank space truncates the value to 1 blank space.
I have even tried inserting another character, then replacing that character with a blank and I still get the truncation.
When I do a test on the string length,it returns the correct result, but the output does not show the blanks in the string.
the code below demonstrates the problem.
Code:
//padding after
$job = '12345';
echo 'start-';
$padLen = str_pad($job, 6,'_');
echo $padLen;
echo '-end';
echo strlen($padLen)."<br>";
echo 'start-';
$padLen = str_pad($job, 10,'/');
echo $padLen;
echo '-end';
echo strlen($padLen)."<br>";
echo strlen($padLen)."~~~";
$padLen = str_replace("/", " ", $padLen);
echo $padLen;
echo '-end';
echo strlen($padLen)."<br>";
Comment