在PHP中进行Html标记

leo*_*dus -2 html php markup

我想用PHP做我的HTML标记使用require这是可能的,如果是这样你怎么做?

现在这是我的index.php中的代码:

<?php


require('header.php')
require('body.php')

htmlHead();
htmlContent();


?>
Run Code Online (Sandbox Code Playgroud)

然后在我的header.php文件中我得到了这个:

<?php

 function htmlHead(){
 echo '
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
            <title>Hello World</title>
            <link rel="stylesheet" href="/style.css" type="text/css">
        </head>';
}


?>
Run Code Online (Sandbox Code Playgroud)

然后为我的身体标签:

<?php
 function htmlContent(){
 echo'  <body>
        <div id="wrapper">
            <p>Hello World!</p>
        </div>
    </body>
</html>
';
}
?>
Run Code Online (Sandbox Code Playgroud)

提前致谢!

Jon*_*hop 5

您不需要将HTML放在函数中.您可以简单地执行以下操作:

require('my_header.php');
Run Code Online (Sandbox Code Playgroud)

而my_header.php的内容如下:

<html>
<head>
  <title>My Title</title>
  <link rel="stylesheet" href="<?php $someVariable; ?>" type="text/css" />
  ...
</head>
Run Code Online (Sandbox Code Playgroud)

十分简单.