【问题标题】:ways to pass variables through php/html file? require()/include() or function()?通过 php/html 文件传递​​变量的方法?需要()/包含()或函数()?
【发布时间】:2012-07-03 12:14:29
【问题描述】:

我有一个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");
?>

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

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

output.php

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

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

谢谢

【问题讨论】:

    标签: php function variables include require


    【解决方案1】:

    在我看来,最好使用函数式方法。该功能可以在多个文件中使用。就Html而言,它可以支持没有这样的问题。我会建议您使用用户功能方法。

    【讨论】:

    • 难道我还需要具有页面功能的 php 才能允许功能工作吗?
    • ya ...您必须包含该文件,但它仍将提供代码的可用性和模块化..
    猜你喜欢
    • 2012-08-07
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    • 2012-11-21
    • 2011-12-15
    • 2011-05-20
    • 2019-12-30
    相关资源
    最近更新 更多