PHP vs ColdFusion/Hello World

From Wikibooks, open books for an open world
Jump to: navigation, search

Hello World was seen as early as 1974 in Bell Laboratorie's internal memorandum by Kernighan —Programming in C: A Tutorial— which shows the first known version of the program:

main( ) {
    printf("Hello, world!");
}

In this tutorial we will use one variable named message to display a string of text.

Putting it Together[edit]

These files should always be created using a program that doesn't include formating, and saves to a non-rich text format such as notepad.exe (Win32), Pico (Command line), Kedit (KDE), or 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>

Line Breakdown[edit]

This is a very simple example because they both do the same thing, in the same amount of code. Not too hard so far eh? Lets see what actually makes them tick...

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

What the Browser Sees[edit]

Either way, these two scripts produce the same exact page, the only thing different are the server headers.

<html>
<head>
<title>Test</title>
</head>
<body>

Hello World!

</body>
</html>

Displayed in Browser[edit]

Hello World!