我应该在HTML中放置一个PHP include / require语句? [英] Where should I put a PHP include/require statement in HTML?

查看:161
本文介绍了我应该在HTML中放置一个PHP include / require语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文件中创建了一个PHP类,现在我想在我的HTML页面中使用它。



我应该将 require include 在HTML页面内部?



在HTML开始或结束时加载它之间是否有性能差异,或者没有差别?



应该是PHP脚本之前的< meta charset =X> ,所以如果类太长,我将不会有任何问题的字符集?



示例:



< pre class =lang-php prettyprint-override> <?php
//我应该在这里加载类吗?

// include/var/www/php/db.php;
// $ classDB ='DB';
// $ bdd = new $ classDB;
?>
<!DOCTYPE html>
< html lang =endir =ltr>
< head>
< meta charset =UTF-8>
< title>无任何< / title>
< / head>
< body>
<?php
$ bdd-> ShowClientList();
?>
< / body>
< / html>
<?php
//或者应该在这里加载类吗?

// include/var/www/php/db.php;
// $ classDB ='DB';
// $ bdd = new $ classDB;
?>


解决方案

依赖它的代码称为。否则放置它不会影响性能。



许多应用程序通常包含文件顶部的文件,因为它更容易跟踪你正在使用那种方式。


I created a PHP class inside a file, and now I want to use it in my HTML pages.

Where should I put the require or include statement inside the HTML page?

Is there a performance difference between load it at the beginning or at the end of the HTML, or is there no difference at all?

Should be the <meta charset="X"> before than the PHP script, so if the class is too long I won't have any problem with the char sets?

Example:

<?php
    //Should I load the class here?

    //include "/var/www/php/db.php";
    //$classDB = 'DB';
    //$bdd = new $classDB;
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
        <meta charset="UTF-8">
        <title>Nothing</title>
    </head>
    <body>
        <?php
          $bdd->ShowClientList();
        ?>
    </body>
</html>
<?php
    //or should I load the class here?

    //include "/var/www/php/db.php";
    //$classDB = 'DB';
    //$bdd = new $classDB;
?>

解决方案

You have to put it anywhere before the code that depends on it is called. Otherwise where you place it won't affect performance.

Many applications typically include files they are dependent on at the top of the file as it makes it easier t keep track of what you're using that way.

这篇关于我应该在HTML中放置一个PHP include / require语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆