Jump to content

Help with str_pad


jwhite68

Recommended Posts

I am trying to simply pad a string with spaces (to the right) so that the total length of the string is 125 characters.

 

$detail2="ab";
$descr = str_pad($detail2,125,' ');
echo 'descr=' . $descr . 'end';

 

If I run this, then the padding does not pad the string with spaces.  However, if I change the ' '  to a '-' it correctly pads with hyphens.  So it suggests the syntax is correct - but maybe there is an issue padding with blank spaces?  I did try without the 3rd argument on the str_pad too, as it should be if you just want to pad with spaces, but that doesnt work either.  Am I missing some quirky setting in PHP?

Link to comment
https://forums.phpfreaks.com/topic/53399-help-with-str_pad/
Share on other sites

Strangely, taith, this is not producing the perfect result.  Its not following the pad characters Ive asked for.

 

$detail2 = "this is a test";
$descr = str_pad($detail2,125, " ");
echo 'descr=' . $descr . 'end';

 

If you run this test you get this result:

 

this is a test                  &nbenddate

 

So its not padding the number of characters asked for, and its appending &nb in ther string. Weird..

Link to comment
https://forums.phpfreaks.com/topic/53399-help-with-str_pad/#findComment-263833
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.