trim - PHP, Triming leading 0s problem -


so here problem getting hex number input filed looks ffff, 000ca3, blah blah blah while trim these down easy $var = ltrim('0',$var);

my problem when user type in '0000' , such trims whole string nothing. if statement on after trim result check string become null , add 0 if does. there other neat trick out there can solve in 1 statement? thank in advance.

here's 1 can think of:

$var = dechex(hexdec($var)); 

hexdec() converts strings actual numeric values, insignificant zeroes — insignificant. dechex() converts them strings once zeroes dropped.

if require uppercase hex a-f digits strange reason, tack on strtoupper() call dechex() produces hex digits in lowercase:

$var = strtoupper(dechex(hexdec($var))); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -