• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

Count characters and add trailing spaces

Hi,

I need format a string,

$string = "this is the string"
$length = 35

If the strlen($string) is < 35 chars I need to write the string with trailing spaces to make up the required length eg:

"this is the string                 "

What's the best way to do this?
0
dougbnv
Asked:
dougbnv
1 Solution
 
RoonaanCommented:
You can use:

$string = str_pad($string, $length);

-r-
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now