DEV Community

Teddy Zugana
Teddy Zugana

Posted on • Updated on

PHP extract PPTX or PPT powerpoint files format to TXT Example

    function pptx_to_text($input_file){
        $zip_handle = new ZipArchive;
        $output_text = "";
        if(true === $zip_handle->open($input_file)){
           $slide_number = 1; //loop through slide files
           while(($xml_index = $zip_handle->locateName("ppt/slides  /slide".$slide_number.".xml")) !== false){
            $xml_datas = $zip_handle->getFromIndex($xml_index);
            $xml_handle = DOMDocument::loadXML($xml_datas, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
           $output_text .= strip_tags($xml_handle->saveXML());
           $slide_number++;
        }
        if($slide_number == 1){
            $output_text .="";
        }
       $zip_handle->close();
   }else{
       $output_text .="";
   }
      return $output_text;
 }
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
krisnewton profile image
krisnewton

Not working