PHP 與 ColdFusion/Hello World
外觀
Hello World 早在 1974 年就被 Kernighan 在 貝爾實驗室 的內部備忘錄中看到——用 C 語言程式設計:教程——它展示了該程式的第一個已知版本
main( ) {
printf("Hello, world!");
}
在本教程中,我們將使用一個名為 message 的 變數 來顯示一串 文字。
這些檔案應始終使用不包含格式化的程式建立,並儲存為非富文字格式,例如 notepad.exe (Win32)、Pico (命令列)、Kedit (KDE) 或 Gedit (GNOME)。
PHP
<html> <head> <title>Test</title> </head> <body> <?php $message = "Hello World!"; echo $message; ?> </body> </html>
ColdFusion
<html> <head> <title>Test</title> </head> <body> <cfset message = "Hello World!"> <cfoutput>#message#</cfoutput> </body> </html>
這是一個非常簡單的示例,因為它們都做著同樣的事情,而且程式碼量相同。到目前為止並不難,對吧?讓我們看看是什麼讓它們真正運轉起來...
PHP
07 <?php 08 $message = "Hello World!"; 09 echo $message; 10 ?>
Line#07 <?php Starts allowing php code to be parsed Line#08 Stores $message with the value Hello World! Line#09 echo Dumps the value Hello World! Line#10 ?> Ends php
ColdFusion
07 <cfoutput> 08 <cfset message = "Hello World!"> 09 #message# 10 </cfoutput>
Line#07 <cfoutput> Starts the ability to output to the browser Line#08 <cfset Stores #message# with the value Hello World! Line#09 #message# Dumps the value Hello World! Line#10 </cfoutput> End the ability to output to the browser
無論哪種方式,這兩個指令碼都產生完全相同的頁面,唯一不同的是 伺服器標頭。
<html> <head> <title>Test</title> </head> <body> Hello World! </body> </html>
Hello World!