I am parsing a docx using PHP to extract the images and text in order using the following code -
$zip = zip_open($filename);
if (!$zip || is_numeric($zip)) return false;
while ($zip_entry = zip_read($zip)) {
if (zip_entry_open($zip, $zip_entry) == FALSE) continue;
$zipEntryName = zip_entry_name($zip_entry);
/*if(preg_match("([^\s]+(\.(?i)(jpg|jpeg|png|gif|bmp))$)",$zipEntryName))
{
echo zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
}*/
if (strpos($zipEntryName, 'word/media') !== false)
{
# Removes 'word/media' prefix
$imageName = substr($zipEntryName, 11);
# Prevent EMF file extensions passing, as they are used by word rather than being manually placed
if (substr($imageName, -3) == 'emf') continue;
# Place the image assets into an array for future reference
$imageAssets[$imageName] = array(
'h' => 'auto',
'w' => 'auto',
'title' => $imageName,
'id' => null,
'data' => base64_encode(zip_entry_read($zip_entry, zip_entry_filesize($zip_entry))));
}
if ($zipEntryName != "word/document.xml") continue;
$content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}
zip_close($zip);
$content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
$content = str_replace('</w:r></w:p>', "\r\n", $content);
$content = str_replace("\r\n", "\n", $content);
$striped_content = strip_tags($content);
I am storing the files in an imageAssets
array. The stripped content contains the entire text along with the image being converted to a random number. How do I map this number to the correct image.