Str_pad not working Str_pad not working php php

Str_pad not working


In HTML you can have only one space shown, but normally in source there are count of spaces, as you wish.

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

There is only one way, how to do it, you have to pad some character (ie. ~) and then replace it with  

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

This will 100% work.


When I echo $string $maint only has 1 space on the right.

The problem is that if you echo your string in HTML code, it will not show all the spaces. If you view source of that page you can see all the spaces added.