Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHPWord在一个文档内重复模板标记替换_Php_Phpword - Fatal编程技术网

PHPWord在一个文档内重复模板标记替换

PHPWord在一个文档内重复模板标记替换,php,phpword,Php,Phpword,我有一个word文档模板文件和变量来填充它(使用mysql),但我不知道如何反复重复这个过程,直到mysql while进程停止,也就是它保存文件并允许用户下载的时候。 例如: 已生成WORD文档: 填充模板 填充模板 填充模板 填充模板 结束文档 允许用户下载文件。您只想用数据库中的内容替换一些变量。您可以这样做: $results=mysql_query(YOUR QUERY HERE); $template='Some contents of the template'; while ($

我有一个word文档模板文件和变量来填充它(使用mysql),但我不知道如何反复重复这个过程,直到mysql while进程停止,也就是它保存文件并允许用户下载的时候。 例如:
已生成WORD文档:
填充模板
填充模板
填充模板
填充模板
结束文档

允许用户下载文件。

您只想用数据库中的内容替换一些变量。您可以这样做:

$results=mysql_query(YOUR QUERY HERE);
$template='Some contents of the template';
while ($row= mysql_fetch_array($results)){
   $template=str_replace($row['template_variable'], $row['value_for_this_template'], $template);
}
echo $template; //template now has the new values stored in the mysql database
然后您将拥有包含mysql值的模板。这假设您有一个mysql表列“template\u variable”,该列最初对应于模板文件中的某个内容,并且该模板的特定输出所需的值位于“value\u for\u This\u template”中


希望有帮助

它将帮助您在PHPWord库中提供一个包含到template.php的函数

对不起,我的意思是该模板实际上是一个word文档,替换的处理过程由PHPWord脚本处理。