- preg_match_all: documentation ( source)
<?php
$str = 'NAME OF ITEM 123456789012
OTHER NAME 987654321098
NAME 567890123456';
preg_match_all( '/^(.*?)\s+((?:^|\D)(\d{12})(?=\D|$))/m', $str, $matches);
$items = array();
foreach( $matches[2] as $k => $upc) {
$items[$upc] = $matches[1][$k];
}
echo $items['987654321098']; // OTHER NAME