PHP/Html 文件转换为 html 文件

PHP/Html file into a html file

我是编码等方面的新手,所以我想从你们那里得到一些帮助。我必须将每个文件 (.php) 放在一个 .html/php 文件中。

现在我得到了这个代码:

    <html>
<head>
    <style type='text/css'>
        span {
            text-decoration:underline;
            color:blue;
            cursor:pointer;
        }
    </style>
    <script>
        // show the given page, hide the rest
        function show(elementID) {
            // try to find the requested page and alert if it's not found
            var ele = document.getElementById(elementID);
            if (!ele) {
                alert("no such element");
                return;
            }

            // get all pages, loop through them and hide them
            var pages = document.getElementsByClassName('page');
            for(var i = 0; i < pages.length; i++) {
                pages[i].style.display = 'none';
            }

            // then show the requested page
            ele.style.display = 'block';
        }
    </script>


</head>
<body>
  <p>
    Show page 
        <span onClick="show('Page1');">1</span>, 
        <span onClick="show('Page2');">2</span>, 
        <span onClick="show('Page3');">3</span>.
    </p>

<div id="Page1" class="page" style="">
    Content of page 1
</div>
<div id="Page2" class="page" style="display:none">
    Content of page 2
</div>
<div id="Page3" class="page" style="display:none">
    Content of page 3
</div>

</body>

所以我的问题是;我如何将我的文件放入 'Content of page 1/2/3'?

提前致谢!

如果您需要将其他 PHP 文件与此 HTML 文件合并,只需将此文件的名称更改为 .php(如果尚未更改)。然后 copy/paste 你的代码(按照每个文件被处理的顺序)放到这个文件的顶部。请务必用 <?php?> 包围您的 php。如果 HTML 在 PHP 文件中,它仍然会正确显示。

注意:这不是好的做法,但它会完成老师的要求。

尝试include("[path to your file]");include_once("[path to your file]");

http://php.net/manual/en/function.include.php

http://php.net/manual/en/function.include-once.php