Jump to content

increase variable from 4 digits to 6 digits


e1seix

Recommended Posts

in my database i have many different unique indentifiers for the various entries, predefined from datafeeds. some of the identifiers are 6 digit codes that begin with 0's eg. 005467. in my database, it cuts the code down to just 5467 which prevents my code from searching acurately.

 

what way could i check, if the code is less than 6 digits - add 0's on the left to make it a 6 digit code... do you see what i mean?

 

cheers,

The real solution is to store the identifiers like strings, and not like numbers. But a PHP solution would be using str_pad():

 

<?php
$id = '5467';
$id = str_pad($id, 6, '0', STR_PAD_LEFT);
//005467
?>

 

Edit: You can just run every number through this BTW - if it's 6 chars long it wont get padded with zeros.

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.