```php title="metadata_extraction.php" metadata; echo "Document Metadata:\n"; echo str_repeat('=', 60) . "\n"; echo "Title: " . ($metadata->title ?? 'N/A') . "\n"; echo "Authors: " . (isset($metadata->authors) ? implode(', ', $metadata->authors) : 'N/A') . "\n"; echo "Subject: " . ($metadata->subject ?? 'N/A') . "\n"; echo "Created By: " . ($metadata->createdBy ?? 'N/A') . "\n"; echo "Producer: " . ($metadata->producer ?? 'N/A') . "\n"; echo "Created: " . ($metadata->createdAt ?? 'N/A') . "\n"; echo "Modified: " . ($metadata->modifiedAt ?? 'N/A') . "\n"; echo "Page Count: " . ($metadata->pageCount ?? 'N/A') . "\n"; echo "Keywords: " . implode(', ', $metadata->keywords ?? []) . "\n"; echo "Language: " . ($metadata->language ?? 'N/A') . "\n\n"; $files = glob('documents/*.{pdf,docx,xlsx}', GLOB_BRACE); $metadataCollection = []; foreach ($files as $file) { $result = extract_file($file); $metadataCollection[] = [ 'file' => basename($file), 'title' => $result->metadata->title ?? 'Untitled', 'author' => isset($result->metadata->authors) ? implode(', ', $result->metadata->authors) : 'Unknown', 'created' => $result->metadata->createdAt ?? 'Unknown', 'pages' => $result->metadata->pageCount ?? 0, 'size' => filesize($file), ]; } echo "Metadata Collection:\n"; echo str_repeat('=', 60) . "\n"; foreach ($metadataCollection as $meta) { echo "{$meta['file']}:\n"; echo " Title: {$meta['title']}\n"; echo " Author: {$meta['author']}\n"; echo " Created: {$meta['created']}\n"; echo " Pages: {$meta['pages']}\n"; echo " Size: " . number_format($meta['size'] / 1024, 2) . " KB\n\n"; } function searchByAuthor(array $collection, string $author): array { return array_filter($collection, function ($meta) use ($author) { return stripos($meta['author'], $author) !== false; }); } function searchByDateRange(array $collection, string $start, string $end): array { return array_filter($collection, function ($meta) use ($start, $end) { $created = $meta['created']; if ($created === 'Unknown') { return false; } $dateOnly = substr($created, 0, 10); return $dateOnly >= $start && $dateOnly <= $end; }); } $johnDocs = searchByAuthor($metadataCollection, 'John'); echo "Documents by John: " . count($johnDocs) . "\n"; $recentDocs = searchByDateRange($metadataCollection, '2024-01-01', '2024-12-31'); echo "Documents from 2024: " . count($recentDocs) . "\n\n"; function generateCatalog(array $collection): string { $html = "
| File | Title | Author | Created | Pages |
|---|---|---|---|---|
| " . htmlspecialchars($meta['file']) . " | "; $html .= "" . htmlspecialchars($meta['title']) . " | "; $html .= "" . htmlspecialchars($meta['author']) . " | "; $html .= "" . htmlspecialchars($meta['created']) . " | "; $html .= "" . htmlspecialchars((string)$meta['pages']) . " | "; $html .= "