Posted By

andreiabohner on 12/27/09


Tagged

Pad Left zeros Fill padding


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

seloh77


Left padding with zeros


 / Published in: PHP
 

fill string with left zeros

  1. $s = "2";
  2. $maxLen = 4;
  3. echo str_pad($s, $maxLen, "0", STR_PAD_LEFT); // "0002"
  4.  
  5. // or
  6.  
  7. echo printf("[%04s]\n", $s); // 0002

Report this snippet  

You need to login to post a comment.