DEV Community

loading...

PHP extract PPTX or PPT powerpoint files format to TXT Example

kevinmel2000 profile image Teddy Zugana Updated on ・1 min read
    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

Discussion

pic
Editor guide