e1seix Posted June 14, 2008 Share Posted June 14, 2008 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, Link to comment https://forums.phpfreaks.com/topic/110220-increase-variable-from-4-digits-to-6-digits/ Share on other sites More sharing options...
thebadbad Posted June 14, 2008 Share Posted June 14, 2008 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. Link to comment https://forums.phpfreaks.com/topic/110220-increase-variable-from-4-digits-to-6-digits/#findComment-565576 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.