Str_pad not working

    **PHP**

    $datearr = explode("/", $cutOff);
    $month = $datearr[0];
    $day = $datearr[1];
    $year = $datearr[2];
    $mainten = "MAINTENANCE";
    $pad=' ';
    $maint = str_pad($mainten, 20, $pad);
    $string = $cduid . $maint . $inarea . $year . $month . $day . "\n";

I am trying to parse this line to the server, and $ maint should be padded with spaces on the right. I also tried .....

    $datearr = explode("/", $cutOff);
    $month = $datearr[0];
    $day = $datearr[1];
    $year = $datearr[2];
    $mainten = "MAINTENANCE";
    $maint = str_pad($mainten, 20);
    $string = $cduid . $maint . $inarea . $year . $month . $day . "\n";

When I echo $ string $ maint has only 1 space on the right. If I replaced $ pad = ''; with $ pad = '.'; I get the correct result, but I need these to be spaces.

What am I missing here?

+4
source share
2 answers

In HTML you can display only one space, but usually the source has as many spaces as you wish.

&nbps; will not work with str_pad because it has 6 characters (in HTML only one character), but for str_pad it does not work.

, , (.. ~),  

$maint = str_replace('~', ' ', str_pad($mainten, 20, '~')); // just use some character you know isn't in your string

100%.

+11

$string $maint 1 .

, HTML, . , .

+1

All Articles