PHP: how to obtain a method or attribute in an object-php Tutorial

Source: Internet
Author: User
Tags phpword ziparchive
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.