How does PHP obtain a method or attribute in an object?
require_once '../PHPWord.php';$PHPWord = new PHPWord();$document = $PHPWord->loadTemplate('Template.docx');print_r($document);exit;
The above is the phpword class. I want to output the content of the word document. I printed the document and output the following content:
We can see that the output in _ documentXML: PHPWord_Template: private is what I want. I don't know how to use php to call this method. Please kindly advise!
Reply to discussion (solution)
But it is a private property.
In this class, a certain method must be used to operate this attribute.
But it is a private property.
In this class, a certain method must be used to operate this attribute.
Thank you. the following is the file of this class. can you help me to see how to call it?
_ TempFileName = paipath.directory_separator.time().'.docx '; copy ($ strFilename, $ this-> _ tempFileName ); // Copy the source File to the temp File $ this-> _ objZip = new ZipArchive (); $ this-> _ objZip-> open ($ this-> _ tempFileName ); $ this-> _ documentXML = $ this-> _ objZip-> getFromName ('Word/document. XML');}/*** Set a Template value ** @ param mixed $ search * @ param mixed $ replace */public function setValue ($ se Arch, $ replace) {if (substr ($ search, 0, 2 )! = '$ {' & Substr ($ search,-1 )! = '}') {$ Search = '$ {'. $ search. '}';} if (! Is_array ($ replace) {$ replace = utf8_encode ($ replace);} $ this-> _ documentXML = str_replace ($ search, $ replace, $ this-> _ documentXML);}/*** Save Template ** @ param string $ strFilename */public function save ($ strFilename) {if (file_exists ($ strFilename )) {unlink ($ strFilename);} $ this-> _ objZip-> addFromString ('Word/document. XML', $ this-> _ documentXML); // Close zip file if ($ this-> _ objZip-> close () = = False) {throw new Exception ('could not close zip file. ');} rename ($ this-> _ tempFileName, $ strFilename) ;}}?>
public function save($strFilename) { if(file_exists($strFilename)) { unlink($strFilename); } $this->_objZip->addFromString('word/document.xml', $this->_documentXML); // Close zip file if($this->_objZip->close() === false) { throw new Exception('Could not close zip file.'); } rename($this->_tempFileName, $strFilename); }
This method is to save to the file
If you want different functions, you can add a method to this class.
public function save($strFilename) { if(file_exists($strFilename)) { unlink($strFilename); } $this->_objZip->addFromString('word/document.xml', $this->_documentXML); // Close zip file if($this->_objZip->close() === false) { throw new Exception('Could not close zip file.'); } rename($this->_tempFileName, $strFilename); }
This method is to save to the file
If you want different functions, you can add a method to this class.
public function show() { if(file_exists($strFilename)) { unlink($strFilename); } return $this->_documentXML; }
Thank you for reminding me that you can set up this method. thank you!
If (file_exists ($ strFilename )){
Unlink ($ strFilename );
}
This is not required!