通过php / html文件传递变量的方法? require()/ include()或function()?

时间:2012-07-03 04:38:54

标签: php function variables include require

我有一个output.php文件,它结合了HTML和PHP内容。

index.php

<?php
     require("output.php");
?>

哪种方式是传递变量的更好方法?我应该

<?php
     $variable = $_GET['r']; //this is some variable that will be passed into output.php
     require("output.php");
?>

或者使用函数()会更好,所以我可以传递某种变量

<?php
     $variable = $_GET['r'];
     echo output($variable);
?>

output.php

function output(variable){
    //html and php
}

但是,我不确定HTML是否可以在函数内部使用?有什么建议吗?

由于

1 个答案:

答案 0 :(得分:0)

据我所知,使用功能方法更好。该函数可以在几个文件中使用。就Html而言,它可以支持没有这样的问题。我建议你使用功能方法。