php模板和html tidyness

php模板和html tidyness,php,templates,Php,Templates,从技术上讲,这可以作为php中的基本级别模板系统吗 因此有两个文件,index.php和Template_Module.php 下面是index.php代码 <?php include("Template_Module.php"); $set_name = "My Website"; $set_desc = "My Website for random bla bla"; $set_key = "site, random, bla, for"; echo template_head

从技术上讲,这可以作为php中的基本级别模板系统吗

因此有两个文件,index.php和Template_Module.php

下面是index.php代码

<?php

include("Template_Module.php");

$set_name = "My Website";
$set_desc = "My Website for random bla bla";
$set_key  = "site, random, bla, for";

echo template_header_object($set_name, $set_desc, $set_key);

  • 是的,这是用PHP制作基本模板的一种非常好的方法。它非常基本,没有提供太多的灵活性,但它是一个快速简单的起点。如果你不需要更复杂的东西,它会很适合你的。(如果您确实需要更复杂的东西,可以使用很多开源PHP模板包)

  • 说真的,不要担心完成的HTML代码看起来如何。无论如何,您不需要查看它(如果需要调试它,请使用浏览器的DOM视图;使用它比查看源代码要容易得多,即使源代码整洁)


  • 您可以使用smarty,这是一个流行的开源php模板系统,或者根据其他注释使用。为什么要重新发明轮子?@BenM我自己是一个自学者,我对PHP的了解是我所知道的,坦率地说,还有很多东西要做。如果我知道或理解php oop,生活会更轻松,但遗憾的是,我尝试过,但似乎无法理解它。所以我被函数所困扰,什么都没有。另外,我不认为smarty包含在我的主机中,因为还有很多其他东西被禁用,比如fileinfo和其他。这就是为什么我要尝试创建一种制作页面的基本方法,这里不会有太多的问题。同样的,rest是动态的。@Cl'你明白了。这就是我的意思。我为引用类和oop向您道歉。在我发布我的评论之前,我没有看到你对此的评论。是你可能感兴趣的好资源。从第159页开始,它讨论oop。这是我个人的喜好。谢谢:)让我开心
    <?php
    
    function template_header_object($set_title, $set_desc, $set_keywords) {
    
         $title_object = htmlspecialchars($set_title);    //lets get html title to pass
         $desc_object  = htmlspecialchars($set_desc);     //lets get meta description to pass
         $keyw_object  = htmlspecialchars($set_keywords); //lets get meta keywords to pass
    
         $template_create_object .= <<<OBJECT
    <!doctype html>
         <html>
             <head>
                 <meta charset="utf-8">
                     <title>$title_object</title>
        <!-- general meta -->
                 <meta name="description" content="$desc_object">
                 <meta name="keywords" content="$keyw_object">
    
        <!-- mobile specific meta -->
                 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">           
    
        <!-- open graph meta -->
                 <meta property="og:title" content="$title_object">
                 <meta property="og:image" content="/assets/img/logo_fbtype.png">
                 <meta property="og:site_name" content="$title_object">
                 <meta property="og:description" content="$desc_object">
    
        <!-- style sheets and scripts -->
                 <link href="/assets/css/style.css" rel="stylesheet">
                 <link href="/assets/css/reset.css" rel="stylesheet">
                 <link href="/assets/img/favicon.png" rel="shortcut icon">
    
                    <!--[if lt IE 9]>
                    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
                    <![endif]-->
    
                 <script src="http://code.jquery.com/jquery-latest.js"></script>
             </head>
         <body></body></html>        
    OBJECT;
    
         return $template_create_object;
    
    }