페이지 당 (mysql) 데이터베이스 행을 포함하는 새로운 RTF 문서를 생성하기위한 템플릿으로 RTF 파일을 사용하려고합니다.PHP를 통해 RTF 템플릿을 구문 분석
제 방법은 생성 된 파일에 첫 번째 행이 있고 각 행에 대해 한 페이지가 아닌 한 페이지 만 포함한다는 점을 제외하면 거의 작동합니다. (내 테스트에는 2 페이지가 있어야합니다).
다음은 주 루프입니다.
class templateParser {
// member definition
var $output;
var $log;
var $replacedTags;
function templateParser($templateFile = 'default_template.htm')
{
// constructor setting up class initialization
$this->log .= "templateParser() called<br />";
if (file_exists($templateFile)) {
$this->log .= 'Found template file ' . $templateFile . '<br/>';
$this->output = file_get_contents($templateFile);
} else {
$this->log .= 'Error:Template file ' . $templateFile . ' not found';
return false;
}
}
function parseTemplate($tags = array())
{
$this->log = 'parseTemplate() called. <br/>';
// code for parsing template files
if (count($tags) > 0) {
foreach($tags as $tag => $data) {
$data = (file_exists($data))? $this->parseFile($data) : $data;
$this->output = str_replace('%' . $tag . '%', $data, $this->output);
$this->log .= 'parseTemplate() replaced <b>' . $tag . '</b> in template<br/>';
$this->replacedTags ++;
}
} else {
$this->log .= 'WARNING: No tags were provided for replacement<br/>';
}
return $this->replacedTags;
}
function parseFile($file)
{
$this->log .= 'parseFile() called. <br/>';
ob_start();
include($file);
$content = ob_get_contents();
ob_end_clean();
return $content;
}
function display()
{
// code for displaying the finished parsed page
return $this->output;
}
}
정확하게 똑같은 것을 찾고 있습니다. 질문에 대한 답을 찾았습니까? –