6.2. Pike 标签

有关 Pike 的完整教程和参考手册,请参阅 http://pike.oav.net/

Pike 标签允许您轻松地将 Pike 代码插入到您的 HTML 页面中,类似于 PHP。如果您有 PHP 背景,或者您想非常轻松地完成操作并且不担心完美的结果,那么这是一个学习 Pike 的好方法。

要做到这一点,您必须在您的服务器中加载一个模块。只需选择加载模块CIF. 中,然后点击 “Pike 标签” 图像。然后点击保存并创建一个 .html 文件,用于存放您的公共 Web 文件。因为大家都告诉我 PHP 很简单,这也是它如此流行的原因,所以我采用了 PHP 示例并将其转换为 Pike。这是结果

示例 6-2. 作为 Pike 标签的 PHP 文档。

<html>
  <body bgcolor="#FFFFFF">
    <h2>Escaping from HTML</h2>
    <p>
      There is one way of escaping from HTML and entering "Pike code mode"
      <br />
      <Pike>
	output("This is the simplest, and SGML processing instruction");
      </Pike>
    </p>
    <h2>Instruction separation</h2>
    <p>
      Instructions are separated the same as in C or Perl: 
      terminate each statement with a semicolon. 
      The closing tag (container, in fact) also implies the end of the statement,
      so the following are equivalent:
      <br />
      <Pike>
	output ("This is a test");
      </Pike>
      <br />
      <Pike> output ("This is a test"); </Pike>
    </p>
    <h2>Comments</h2>
    <p>
      Pike supports C, C++ but not Unix shell-style comments. For example:
      <Pike>
	string tests = "This is a test<br />";  // this is a one-line C++ style comment
	/* This is a multi line comment
         yet another line of comment */
	tests += "Yet another test";
	return tests;
      </Pike>
    </p>
    <h2>Melding RXML and Pike</h2>
    You will never see this in PHP.
    [1]
    This will create a .gif image of 1-2-...-255. 
    This took 0.4s on my Duron 750 the first time and 0.1s after.
    <p>
      <gtext scale=0.5>
	<Pike>
	  string output = "";
	  for(int I = 1; I < 255; I++) 
	    output += I + "-";
	  return output;
	</Pike>
      </gtext>
    </p>
  </body>
</html>
      

使用它的问题是您很快就会发现它不够强大

下一步是编写您的第一个 Pike 脚本。

注释

[1]

事实上你可以... 只是为 Caudium 编译 PHP :)