Hi,
how to get <w:lastRenderedPageBreak/>, <w:tab/>,<w:t xml:space="preserve"> from document?
i tried getWordStyles and getWordContents, but not working well.
Hi,
how to get <w:lastRenderedPageBreak/>, <w:tab/>,<w:t xml:space="preserve"> from document?
i tried getWordStyles and getWordContents, but not working well.
Hello,
getWordStyles returns styles information. getWordContents returns text contents. If you need to get tags (XML) information you can use getDocxPathQueryInfo, that returns an array with elements and other information. In the package you can find some samples using it.
Regards.
$docx = new CreateDocxFromTemplate('wordUpload/test.docx');
$asd = array(
'type' => 'paragraph',
'contains' => 'BACKGROUND OF THE INVENTION'
);
$queryInfo = $docx->getDocxPathQueryInfo($asd);
print_r($queryInfo);
when i use getDocxPathQueryInfo,
i only return like this.
Array ( [elements] => DOMNodeList Object ( [length] => 1 ) [length] => 1 [query] => //w:body/w:p[1=1 and contains(., 'BACKGROUND OF THE INVENTION')] )
How can i get tags?
Hello,
You can iterate the DOMNodeList object ('elements' key) to get each element (including XML tags):
foreach ($queryInfo['elements'] as $element) {
...
}
DOMNodeList is a PHP DOM object: https://www.php.net/manual/en/class.domnodelist.php, so you can use all PHP DOM methods (https://www.php.net/manual/en/book.dom.php) to get XML strings, query tags, get attributes...
Regards.
$docx = new CreateDocxFromTemplate('wordUpload/0hwkiexKKE22-00723_up.docx');
$asd = array(
'type' => 'paragraph',
'contains' => '上記回動軸ã¯ã€ä¸Šè¨˜å…‰è»¸ã¨ãã˜ã‚Œã®é–¢ä¿‚ã«ã‚ã‚‹ã€å…‰å¦ç³»ã€‚'
);
$queryInfo = $docx->getDocxPathQueryInfo($asd);
foreach ($queryInfo['elements'] as $element) {
$attributes = $element->attributes;
if(!is_null($attributes))
{
foreach ($attributes as $index=>$attr)
{
echo $attr->name."=\"".$attr->value."\"";
}
}
}
paraId="2C1EECD0"textId="77777777"rsidR="004F0C7A"rsidRPr="004F0C7A"rsidRDefault="004F0C7A"rsidP="004F0C7A"
i only get that.
<w:p w14:paraId="2C1EECD0" w14:textId="77777777" w:rsidR="004F0C7A" w:rsidRPr="004F0C7A" w:rsidRDefault="004F0C7A" w:rsidP="004F0C7A">
<w:r w:rsidRPr="004F0C7A">
<w:tab/>
</w:r>
<w:r w:rsidRPr="004F0C7A">
<w:t>上記回動軸ã¯ã€ä¸Šè¨˜å…‰è»¸ã¨ãã˜ã‚Œã®é–¢ä¿‚ã«ã‚ã‚‹ã€å…‰å¦ç³»ã€‚</w:t>
</w:r>
</w:p>
i want to get if this sentence has <w:lastRenderedPageBreak/>, <w:tab/>,<w:t xml:space="preserve">;
how can i?
Hello,
attributes only return the attributes of the element. To query tags in a PHP DOM object, you need to use getElementsByTagName or getElementsByTagNameNS available in PHP DOM. Or use PHP XPath (https://www.php.net/manual/en/domxpath.query.php).
Please note that this is not a phpdocx question but a PHP DOM question. We recommend you read more information on the PHP DOM documentation (https://www.php.net/manual/en/book.dom.php).
Regards.