fork download
  1. <?php
  2.  
  3. $text = '8 digit 12345678 and now 12 digit 123456789012';
  4. $extractGTIN = '/\b\d{8}(?:\d{4,6})?\b/';
  5. preg_match_all($extractGTIN, $text, $barcodes);
  6. print_r($barcodes[0]);
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 12345678
    [1] => 123456789012
)