I have a convertor which will convert doc and docx to html for that convertor the class file is as follows
<?php
class docxhtml {
public $connectname;
public $connectpass;
public function __construct($format_res, $flname) {
require_once('config.php');
// Turn up error reporting
error_reporting (E_ALL|E_STRICT);
// Turn off WSDL caching
ini_set ('soap.wsdl_cache_enabled', 0);
// Define credentials for LD
define ('USERNAME', $this->connectname);
define ('PASSWORD', $this->connectpass);
// SOAP WSDL endpoint
define ('ENDPOINT', 'https://api.livedocx.com/2.1/mailmerge.asmx?wsdl');
// Define timezone
date_default_timezone_set('Europe/Berlin');
// Instantiate SOAP object and log into LiveDocx
$this->soap = new SoapClient(ENDPOINT);
$this->soap->LogIn(
array(
'username' => USERNAME,
'password' => PASSWORD
)
);
// Upload template
$this->data = file_get_contents('Original/'.$format_res);
$this->soap->SetLocalTemplate(
array(
'template' => base64_encode($this->data),
'format' => 'docx'
)
);
$this->result = $this->soap->RetrieveDocument(
array(
'format' => 'html'
)
);
$this->data = $this->result->RetrieveDocumentResult;
file_put_contents('Recode/'.$flname.'.html', base64_decode($this->data));
}
}
?>
As you can see this class file send the converted file to Recode folder which will then get downloaded by save dialog box by a script in front end PHP..
Now what i need guidance was .. I want to convert that Resulting HTML to clean stripped html for which i did a code as follows which works well
<?php
$path = 'path to previous html output file from local machine';
$html = file_get_contents($path);
$dom = new DOMDocument();
//$dom->strictErrorChecking = false;
$dom->formatOutput = true;
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
if (false === ($elements = $xpath->query("//*"))) die('Error');
foreach ($elements as $element) {
for ($i = $element->attributes->length; --$i >= 0;) {
$name = $element->attributes->item($i)->name;
if (('img' === $element->nodeName && 'src' === $name)
|| ('a' === $element->nodeName && 'href' === $name)
) {
continue;
}
$element->removeAttribute($name);
}
}
echo $dom->saveHTML();
?>
Now i want to merge these two .. i.e in the 1st class file before it stores the data to recode folder it should process this dom codes and then save that output to that recode folder .. Kindly guide me please