哪个更快?主脚本或变量脚本

时间:2010-01-30 20:01:16

标签: php templates

其中哪些会提供最多功能?

在变量中定义模板:

elseif($global[action] == "edit_template") {
    $template_content = template_get($_GET['template']);
    $template_content = str_replace('\"', '"', $template_content);
    $template_content = str_replace('</textarea>', '&lt;/textarea&gt;', $template_content);
    $template = db_get_array("templates","name='$_GET[template]'");
    $output_template = template_get("Admin Edit Template");
}

或将它们放在主脚本中

$template_content = template_get($_GET['template']);
$template_content = str_replace('\"', '"', $template_content);
$template_content = str_replace('</textarea>', '&lt;/textarea&gt;', $template_content);

换句话说,最好是将所有模板缓存在脚本顶部,还是只调用所需的操作变量?

2 个答案:

答案 0 :(得分:2)

假设你只分配了一次变量,它确实没有区别。函数需要一定的时间,这有助于脚本的总时间,无论函数在脚本中的哪个位置。

更复杂的函数可能需要更长时间在脚本中的不同点(例如解析输出缓冲区),而不是变量赋值

答案 1 :(得分:0)

我认为将它们放在if子句中是最有效的,因为只有在执行该特定操作时才会执行该代码。我假设你在这个剧本中有一堆其他的。

相关问题