PHP code example of tacman / nitf-parser

1. Go to this page and download the library: Download tacman/nitf-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tacman / nitf-parser example snippets


use Tacman\NTF\NTF;

// Parse from file
$ntf = NTF::fromFile('article.xml');

// Or from XML string
$ntf = NTF::fromXml($xmlString);

// Or from a zip archive containing multiple NITF files
foreach (NTF::fromZip('articles.zip') as $ntf) {
    echo $ntf->headline;
}

// Get a flat array ready for indexing
$searchable = $ntf->toSearchable();

$ntf = NTF::fromFile('article.xml');
$searchable = $ntf->toSearchable();

// Index directly into Meilisearch
$client->index('articles')->addDocuments([$searchable]);

// Iterate through all NITF files in a zip
$count = 0;
foreach (NTF::fromZip('archive.zip') as $ntf) {
    $count++;
    // Process each document
}

// Or get all as an array
$all = NTF::allFromZip('archive.zip');

$ntf->id;           // "abc123"
$ntf->headline;    // "Big Game Today"
$ntf->subhead;     // "Preview and analysis"
$ntf->byline;      // "By John Smith"
$ntf->body;        // "First paragraph...\n\nSecond paragraph..."
$ntf->keywords;     // ["#news", "#sports"]
$ntf->section;     // "news/sports"
$ntf->publishedAt; // DateTime object