php读取对象属性,PHP如何获取对象里的一个方法或者属性

require_once '../PHPWord.php';$PHPWord = new PHPWord();$document = $PHPWord->loadTemplate('Template.docx');print_r($document);exit;

上面是phpword类,我现在想输出word文档的内容,我打印了一下document ,输出的是如下内容:

可以看到_documentXML:PHPWord_Template:private 这个里面输出的就是我想要的,不知道如何用php调用到这个方法。求大神指教!

回复讨论(解决方案)

但那是私有的属性

在这个类中,一定有某个方法是用来操作这个属性的

但那是私有的属性

在这个类中,一定有某个方法是用来操作这个属性的

谢谢,下面是这个类的文件,能不能帮忙看一下如何调用啊_tempFileName = $path.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($search, $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); }这个方法就是保存到文件

如果你想要不同的功能,可以给这个类加个方法

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 show() { if(file_exists($strFilename)) { unlink($strFilename); } return $this->_documentXML; }

谢谢您提醒,建立这个方法可以了,感谢!

if(file_exists($strFilename)) {

unlink($strFilename);

}

这个不要!

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值