简体   繁体   English

如何在c中包含HTML文件

[英]How do you include a HTML file in c

I am currently using g-wan for myweb server and would like to know How do you merger multiple HTML files, in c for HTML? 我目前正在将g-wan用于myweb服务器,并且想知道如何在c for HTML中合并多个HTML文件?
In php I t would be 在PHP中我会

<?php include('/path/to/file.php');?>

How would you do this in c for gwan? 您将如何在c for gwan中执行此操作?

The PHP include statement loads a static file from disk to build the PHP output. PHP include语句从磁盘加载一个静态文件以构建PHP输出。 The included file can be both PHP code or HTML text. 包含的文件可以是PHP代码或HTML文本。 The PHP pre-processor will just blindly load the file and let it be interpreted by the PHP interpreter. PHP预处理器只会盲目地加载文件,并由PHP解释器对其进行解释。

The C language can be the same thing for C source code with the #include directive, but not for raw HTML text, unless it has been placed in a C array (as shown here in the static char top[] array). C语言可以是用于与所述C源代码同样的事情#include指令,而不是用于原始HTML文本中,除非它被放置在一个C阵列(如所示在这里static char top[]数组)。

This is the most efficient option because the file is already part of the source code file. 这是最有效的选择,因为该文件已经是源代码文件的一部分。 The downside is that the contents may be duplicated if you need them from different C scripts. 缺点是,如果您需要其他C脚本中的内容,则可能会重复这些内容。

If this overhead is unacceptable, you can also load the file dynamically (at the cost of more disk I/O) as shown here , search for the xbuf_frfile(&buf, szfile); 如果这一开销是不可接受的,还可以动态地加载该文件(在更多的磁盘I / O的成本),如图这里 ,搜索xbuf_frfile(&buf, szfile); line of code. 代码行。

Note that as PHP, an interpreted language, is written in C and/or C++, the PHP include statement is most probably using the C option #2 above, hence the better performance when using PHP code caches because the included file is loaded only one time (at the cost of contents duplication, like the C option #1 describbed above). 请注意,由于PHP是一种解释性语言,是使用C和/或C ++编写的,因此PHP include语句很可能使用上述C选项#2,因此,在使用PHP代码缓存时,由于包含的文件仅加载一个,因此性能更好。时间(以内容重复为代价,例如上面描述的C选项#1)。

To sum it up, C lets you pick the method you want, when you want. 综上所述,C使您可以在需要时选择所需的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM