在没有Webserver的情况下解析HTML内容 [英] Parsing PHP content in HTML without Webserver

查看:91
本文介绍了在没有Webserver的情况下解析HTML内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个只有html页面的简单webiste。我现在在每个文件中都包含Header,侧边栏和页脚,这是多余的。所以,在寻找解决方案时,我发现<?php include ,可以帮助我。但我的浏览器不解析php内容。我怎样才能让它解析PHP文件的HTML?



谢谢

因为你的目标是创建一个简单的HTML网站,所以使用静态页面我不认为PHP是最好的选择。



你有两个选择:



在您的本地计算机上运行PHP以预处理文件:



如果你安装了PHP-cli(命令行客户端),你可以用它来处理你的PHP静态页面。将它的输出重定向到一个文件,并且你有你想要的输出:

  php-cli index.php> index.html 

使用nanoc(基于ruby的)构建您的静态网站:<< code<< ;?php include('file')?> 在学习HTML时。



考虑到这一点,我建议您查看 nanoc 。它是一种使用ruby来帮助创建静态HTML网页的工具,它提供了定义布局的方法(您正在使用PHP的 include )以及其他许多功能。 p>

使用和生成静态HTML文件非常简单,您可以将它们上传到任何服务器或直接用浏览器打开,并且在开发您的网站时仍可启用许多强大的功能。


I want to create a simple webiste with only html pages. I am now including Header, sidebar, footer in every file, which is redundant. So, while looking for solution, I found <?php include, can help me. But my browser is not parsing php content. How can I make it parse php files in html?

Thank you

解决方案

Since your goal is to create a simple HTML website, with static pages I don't think PHP is the best way to go.

You have two options:

Run PHP on your local computer to pre-process the files:

If you install PHP-cli (command line client), you can use it to process your PHP static pages. Redirect its output to a file and you have your desired output:

php-cli index.php > index.html

Use nanoc (ruby-based) to build your static website:

If you don't have a webserver with PHP enabled, I assume you do not have PHP as a requirement but rather found about <?php include('file') ?> while studying HTML.

With this in mind, I suggest you check out nanoc. It's a tool what uses ruby to help creating static HTML webpages, by providing ways to define a layout (what you're doing with PHP's include) and many other features.

It's quite simple to use and produces static HTML files that you can upload to any server or open with your browser directly and still enables many powerful features while developing your website.

这篇关于在没有Webserver的情况下解析HTML内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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