PHP remove first zeros

James picture James · Aug 25, 2010 · Viewed 49k times · Source

Want to remove all 0 placed at the beginning of some variable.

Some options:

  1. if $var = 0002, we should strip first 000 ($var = 2)
  2. if var = 0203410 we should remove first 0 ($var = 203410)
  3. if var = 20000 - do nothing ($var = 20000)

What is the solution?

Answer

drAlberT picture drAlberT · Aug 25, 2010

cast it to integer

$var = (int)$var;