title: Generate valid EAN13 in PHP
body: <p>There are alot of classes to generate barcode image, but I can't find a function that would create valid EAN13 number. Internal numbers should start with 200 ... how do I generate a valid EAN13 number that would be next valid EAN to given value?</p>
  
  <p>Validation function looks like this:</p>
  
  <pre><code>function ean13_check($digits){
      if($digits &lt;= 0) return 0;
      while(strlen($digits) &lt; 13){
          $digits = '0'.$digits;
      }
      $digits=preg_split("//",$digits,-1,PREG_SPLIT_NO_EMPTY);
      $a=$b=0;
      for($i=0;$i&lt;6;$i++){
          $a+=(int)array_shift($digits);
          $b+=(int)array_shift($digits);
      }
      $total=($a*1)+($b*3);
      $nextten=ceil($total/10)*10;
      return $nextten-$total==array_shift($digits);
  }
  </code></pre>