Ads Inside Post

Search in This Blog

Show DOCX meta data in php

Show DOCX meta data in php

 

 <?php
/*<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <dc:title>Title Proforma-For-Application</dc:title>
  <dc:subject>Subject Proforma-For-Application.docx<

/dc:subject>
  <dc:creator>MICROSOFT2012</dc:creator>
  <cp:keywords>Keywords Proforma-For-Application.docx</cp:keywords>
  <dc:description>This is comments Proforma-For-Application.docx</dc:description>
  <cp:lastModifiedBy>MICROSOFT2012</cp:lastModifiedBy>
  <cp:revision>11</cp:revision>
  <dcterms:created xsi:type="dcterms:W3CDTF">2013-07-17T11:50:00Z</dcterms:created>
  <dcterms:modified xsi:type="dcterms:W3CDTF">2013-07-17T12:06:00Z</dcterms:modified>
  <cp:category>Category Proforma-For-Application.docx</cp:category>
</cp:coreProperties>
*/
class Docx{
    var $xml_data = "";
    function openDocx($path_of_file) {
        $zip = new ZipArchive;
        $ans = $zip->open($path_of_file);
        if ($ans === TRUE) {
            $folder = uniqid("", true);
            mkdir($folder, 0700);
            $zip->extractTo($folder, array("docProps/core.xml"));
            $zip->close();
            $this->xml_data = file_get_contents($folder."/docProps/core.xml");    
            unlink($folder."/docProps/core.xml");
            rmdir($folder."/docProps");
            rmdir($folder);
        }                
    }
        
    function showTitle(){
        $title_start = explode("</dc:title>", $this->xml_data);    
        //$meta_title_end = explode("<dc:title>", $meta_title_start[0]);
        //return $meta_title_end[1];    
        return (explode("<dc:title>", $title_start[0])[1]);    
    }
        
    function showSubject(){
        $subject_start = explode("</dc:subject>", $this->xml_data);    
        return (explode("<dc:subject>", $subject_start[0])[1]);    
    }
        
    function showCreator(){
        /*$creator_start = explode("</dc:creator>", $this->xml_data);    
        $creator_end = explode("<dc:creator>", $creator_start[0]);    
        return $creator_end[1];*/    
        //$creator_end = explode("<dc:creator>", (explode("</dc:creator>", $this->xml_data))[0]);    
        return (explode("<dc:creator>", explode("</dc:creator>", $this->xml_data)[0])[1]);
    }
        
    function showKeywords(){
        $keywords_start = explode("</cp:keywords>", $this->xml_data);    
        $keywords_end = explode("<cp:keywords>", $keywords_start[0]);    
        return $keywords_end[1];
    }
        
    function showDescription(){
        $description_start = explode("</dc:description>", $this->xml_data);    
        $description_end = explode("<dc:description>", $description_start[0]);    
        return $description_end[1];
    }
        
    function showLastModifiedBy(){
        $lastmodifiedby_start = explode("</cp:lastModifiedBy>", $this->xml_data);    
        $lastmodifiedby_end = explode("<cp:lastModifiedBy>", $lastmodifiedby_start[0]);    
        return $lastmodifiedby_end[1];
    }
        
    function showRevision(){
        $revision_start = explode("</cp:revision>", $this->xml_data);    
        $revision_end = explode("<cp:revision>", $revision_start[0]);    
        return $revision_end[1];
    }
        
    function showDateCreated(){
        $datecreated_start = explode("</dcterms:created>", $this->xml_data);    
        $datecreated_end = explode("<dcterms:created xsi:type=\"dcterms:W3CDTF\">", $datecreated_start[0]);    
        return $datecreated_end[1];
    }
        
    function showDateModified(){
        $datemodified_start = explode("</dcterms:modified>", $this->xml_data);    
        $datemodified_end = explode("<dcterms:modified xsi:type=\"dcterms:W3CDTF\">", $datemodified_start[0]);    
        return $datemodified_end[1];
    }
        
    function showCategory(){
        $category_start = explode("</cp:category>", $this->xml_data);    
        $category_end = explode("<cp:category>", $category_start[0]);    
        return $category_end[1];
    }
}
$docx = new Docx();
$docx_file_name_with_path = "Proforma-For-Application.docx";
$docx->openDocx($docx_file_name_with_path);
echo "<strong>File : ",$docx_file_name_with_path . "</strong><br>";
echo "Title : " , $docx->showTitle() . "<br>";
echo "Subject : " , $docx->showSubject() . "<br>";
echo "Author : " , $docx->showCreator() . "<br>";
echo "Category : " , $docx->showCategory() . "<br>";
echo "Keywords : " , $docx->showKeywords() . "<br>";
echo "Comments : " , $docx->showDescription() . "<br>";
echo "Last Modified By : " , $docx->showLastModifiedBy() . "<br>";
echo "Revision : " , $docx->showRevision() . "<br>";
echo "Created on: " , $docx->showDateCreated() . "<br>";
echo "Modified on: " , $docx->showDateModified() . "<br>";
?>