我正在尝试使用phpword在生成的文档中插入一个脚注。 假设:
WSDL
现在我想在括号内加上文字" []"作为脚注插入。我不知道如何处理这个问题。也许你在这里明白这一点: http://phpword.readthedocs.org/en/latest/elements.html#footnotes-endnotes
答案 0 :(得分:0)
好的,自己做了。但这并不意味着它是万无一失的:
$content = "Line\r\nAnother Line\r\nYetß [önd my footnoteü] anotherß [änd my footnote2] line\r\nfinal line";
$section = $phpWord->addSection();
$textlines = preg_split("/(\r\n|\r|\n)/", $content);
foreach($textlines as $line) {
# check for footnotes
if (preg_match("/\[.+?\]/", $line)) {
$textrun = $section->addTextRun();
$chunk_array=preg_split("/([\[\]])/", $line, -1, PREG_SPLIT_DELIM_CAPTURE);
foreach ($chunk_array as $chunk) {
# open
if ($chunk=="[") {
$openit=true;
$closeit=false;
continue;
}
if ($chunk=="]") {
$openit=false;
$closeit=true;
continue;
}
if ($openit) {
$footnote = $textrun->addFootnote();
$footnote->addText(htmlspecialchars($chunk));
} else {
$textrun->addText(htmlspecialchars(rtrim($chunk)));
}
#print $chunk."\n";
}
} else {
$section->addText(htmlspecialchars($line));
}
}