We recently had to extract barcode data from a large directory of .lbx files, which is the file format used by Brother P-Touch Label Printer software. We could have found the software, opened each file in turn and cut and pasted the data into a spreadsheet, but this didn’t seem very efficient.
Opening the files in a text editor revealed that .lbx files are actually standard zip files – if you change the extension from .lbx to .zip you can open them up to reveal two files inside – label.xml and prop.xml, both standard XML files. The contents of the label can then be found by opening the label.xml file and looking for a node called ‘pt:data’.
We wrote a quick and dirty PHP 5.2 script that extracts all the label data and displays it in a basic html table:
// Eg my_web_server_dir/data_dir/
$labelsDirectory = 'labels';
echo '<table>';
foreach (new DirectoryIterator($
if ($fileInfo->isDot() || (!stripos($fileInfo->
continue;
}
$zip = zip_open($labelsDirectory . '/' . $fileInfo->getFilename());
do {
$entry = zip_read($zip);
if (!is_resource($entry)){
continue;
}
$entryName = zip_entry_name($entry);
if (trim((string)$entryName) != 'label.xml') {
continue;
}
$entryContent = zip_entry_read($entry, zip_entry_filesize($entry));
$xml = simplexml_load_string($
$matches = $xml->xpath('//pt:data');
$barcode = '????';
if (isset($matches[0])) {
$barcode = $matches[0]->__toString();
}
echo '<tr><td>' . str_replace('_', ' ', str_replace('.lbx', '', $fileInfo->getFilename())) . '</td><td>' . $barcode . '</td></tr>';
} while ($entry);
}
echo '</table>';
Thank you milion times!