急急急急急急急急急急急!!!!

zhangjy2001 2003-05-07 08:34:41
有没有工具可以把HTML格式转化CGI格式的!!

html: <br><div align=center><table><tr><td>
就象 C: printf("<br><div align=center><table><tr><td>\n");
就是在HTML后面自动加上\n.

...全文
47 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengliyong 2003-05-08
  • 打赏
  • 举报
回复
我现写的,只是个测试,你看行不行
#include <iostream>
#include <fstream>
using namespace std;
#include <stdlib.h>

int main(int argc, char *argv[])
{
ifstream HtmlFile( "test.html" ); //html Îļþ
while(!HtmlFile)
{ cerr << "Can not open test.html file\n"; exit(-1); }
ofstream CppFile( "test.cpp" ); //printf¸ñʽÎļþ
while(!CppFile)
{ cerr << "Can not open test.cpp file\n"; exit(-1); }

char Buffer[65535]; //¼ÙÉèÒ»ÐÐ×î´ó65535¸öbyte
int LineLongth;
while(!HtmlFile.eof())
{
HtmlFile.getline(Buffer,65535,'\n');
LineLongth = strlen(Buffer);
CppFile << " printf(\""; //´òÓ¡pirntf("
for( int ix = 0 ; ix < LineLongth; ix++ )
{
if(Buffer[ix]=='"') // Èç¹ûÓöµ½"¾Í¼ÓÈë'\'
CppFile << "\\" ;
CppFile << Buffer[ ix ];
}
CppFile << "\\n\");" << endl; //´òÓ¡\n");
}

HtmlFile.close();
CppFile.close();
system("PAUSE");
return 0;
}
tuya000000 2003-05-08
  • 打赏
  • 举报
回复
这个…………
我只能说用程序来实现这个功能是可行的,但是目前还没有看到过类似的工具

介绍你一个相对轻松的手工修改方法吧(只有perl可以)
假设有如下代码
<br><div align=center>
<table>
<tr>
<td>
12345
</td>
</tr>
</table>
</div>

在perl环境下就可以改为
print "<br><div align=center>
<table>
<tr>
<td>
12345
</td>
</tr>
</table>
</div>";

也就是说在一段html的前面加上“print "” 后面加上“";” 就行了
当然,输出的html代码中的特殊字符(如“"”)需要进行转义(改成“/"”,或者不用

还有就是切换html/text模式
还是以perl为例
html页下:
----------------
<br><div align=center>
<table>
<tr>
<td>
12345
</td>
</tr>
</table>
</div>
-----------
CGI环境下
-----------
print <<"EOM";
<br><div align=center>
<table>
<tr>
<td>
12345
</td>
</tr>
</table>
</div>
EOM
-------------

效果是一样的

2,203

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 CGI
社区管理员
  • CGI社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧