하나의 해결책은 같은 코드를 작성하는 것입니다 :
// Creates a template of category
$page = <<< EOT
<html>
<head>
<title>Category {$category_name}</title>
(...)
</body>
</html>
EOT;
$f = fopen($new_directory . "/index.php", 'w');
fwrite($f, $page);
fclose($f);
Remeber이 EOT를 넣어를; 문서의 가장 왼쪽에 있습니다. 자세한 내용은 heredoc syntax을 참조하십시오.
이 코드는 샘플이므로 fopen/fwrite가 성공했는지 확인해야합니다.
또 다른 솔루션은 템플릿 토큰이있는 다른 파일에 템플릿을 포함 할 수 있습니다.
같은 방법으로
, 당신이 들어있는 파일의 이름 template_category.txt해야합니다 :
$template = file_get_contents("template_category.txt");
$to_replace = array(
'%category_name%',
(...)
);
$replace_by = array(
$category_name,
(...)
);
$page = str_replace($to_replace, $replace_by, $template);
:
<html>
<head>
<title>Category %category_name%</title>
(...)
</body>
</html>
를 그런 다음, PHP 스크립트를, 당신은 당신의 값으로 템플릿 토큰을 대체 할 수 있습니다
그리고 위와 같이 index.php에 $ page를 씁니다.
템플릿으로 이동 – Kuro
편집 ...하지만 현재 카테고리가 열린이 코드 변수에 저장해야합니다. –