0
zip_read()
を使用して.docxファイルを読み込んでいますが、.docxではページ区切りが<w:br w:type="page"></w:br>
となっています。私はそれを<br style="page-break-before: always">
に変えて、HTMLに出力することができます。どうやってやるの?ありがとう!PHPを使って.docxの改行をHTMLの改行に変換するには
zip_read()
を使用して.docxファイルを読み込んでいますが、.docxではページ区切りが<w:br w:type="page"></w:br>
となっています。私はそれを<br style="page-break-before: always">
に変えて、HTMLに出力することができます。どうやってやるの?ありがとう!PHPを使って.docxの改行をHTMLの改行に変換するには
あなたはDOMでそれを読むことができるので、これは、XMLファイル形式です:要求されたように、これは、HTMLページ区切りに単語改ページを変換します
$xml = <<< WORD
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
<w:body>
<w:br w:type="page"></w:br>
</w:body>
</w:wordDocument>
WORD;
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadXML($xml);
libxml_clear_errors();
$xpath = new DOMXPath($dom);
$xpath->registerNamespace('w', 'http://schemas.microsoft.com/office/word/2003/wordml');
// find all the page breaks
foreach ($xpath->evaluate('//w:br[@w:type="page"]') as $page_break) {
// create an html break element with some style attribute
$html_break = $dom->createElement('br');
$html_break->setAttribute('style', 'page-break-before: always');
// replace the page break with the html break in the document
$page_break->parentNode->replaceChild($html_break, $page_break);
}
echo $dom->saveHTML();
:
<?mso-application progid="Word.Document"><w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
<w:body>
<br style="page-break-before: always">
</w:body>
</w:wordDocument>
ないこと、それはxmlという言葉の残りの部分がそのままであることを考えると、かなり意味をなさないでしょう。しかし、それはXMLパーサーを使ってそれを処理する方法です。
確認が同様
方法については 'str_replace'をhttps://github.com/PHPOffice/PHPWordをチェックするようにしてください? – rtfm
は動作していないようです – user2335065
あなたのコードでは推測できません。 – rtfm