Google Answers Logo
View Question
Q: Difference between Pascal & PHP ( Answered 5 out of 5 stars,   0 Comments )
Subject: Difference between Pascal & PHP
Category: Computers > Programming
Asked by: whitehat88-ga
List Price: $20.00
Posted: 05 Jun 2005 07:40 PDT
Expires: 05 Jul 2005 07:40 PDT
Question ID: 529542
Can someone tell me the difference between those two programming
languages? Also please show as many code snippets of both languages as
Subject: Re: Difference between Pascal & PHP
Answered By: djbaker-ga on 05 Jun 2005 10:37 PDT
Rated:5 out of 5 stars
Without even looking at the Syntax differences between the two, PHP
and PASCAL are two very different languages.  Unlike a comparison
between other languages such as C and Basic or C++, the differences do
not simply lie in how flexible or powerful the languages are but
rather in their basic use.  At its core PHP is designed as a scripting
language to be used server-side while PASCAL is a regular programming
language which can be used to write standalone applications.

PHP has become an incredibly popular language recently.  Its use can
be seen through out the web, from simple form processing scripts to
giant web based applications such as MediaWiki, the engine which
drives  PHP is a scripting language, so in
terms of use and flexibility it has a lot in common with other
scripting languages such as Perl, Python and Ruby.

PHP is designed to be run server-side and is primarily used to enhance
website functionality.  So for example if you wanted a program which
took user submitted data from a form on your website and added it to a
database you would want to write a PHP script.  Scripts can also be
written which parse data, interact with users, etc.  The only major
limitation to PHP is that it is designed to run server-side so it
cannot for most practical purposes to be used to create standalone

This is where PASCAL comes into play.  Where PHP is designed to be run
server-side, PASCAl is designed to be run client side.  This mean
instead of a server processing the program and feeding the information
to the end user, PASCAL is used to create programs which run on the
users computer.

PASCAL was developed in 1970 by Niklaus Wirth.  The language has
fallen out of use in recent years in favor of more popular languages
such as C, C++ and Java.  Some of the notable things that have been
developed in PASCAL include large portions of the original Macintosh
Operating System as well as the typesetting system TeX.

If you wanted to write a piece of shareware or a regular program which
stands alone and does not require a server then PASCAL (instead of
PHP) is what you would want to use.  In practical terms though not
much is written in PASCAL these days.

----- Code Samples ---------------
Below you'll find some code samples for the two languages which
illustrate some of the syntax differences for some of the more common

*** File Format  ***
A PHP script is saved with the format filename.php.  When placed on a
PHP enabled server and run it will be interpreted by the server's PHP
parser and executed.

A Pascal program on the other hand is written in a text editor and
then compiled which creates an executable program with the extension
(on a PC) .exe.

*** Beginning and Ending ***
PHP scripts begin with the tag: <?PHP and end with ?>

So a script would look like this...


... Your script here ...


In PASCAL programs start with the "Program" keyword and then the main
block of code is contained within begin and end tags.  So a sample
PASCAL program would look like this...

program YourProgram(input, output)
	... Your Code Goes Here ...

*** Basic Variables ***
PHP does not have defined variable types.  As a result all variables
are prefixed with $.  So the variable named "variable"  would look
like $variable.

Variables in Pascal are similar to those in C and other languages. 
Check out this nice tutorial for examples on how to define the various
variable types in PASCAL.

*** If/Then ***
If/Then statements in PHP are fairly easy to write.  It begins with an
If(X) where represents the condition to be evaluated.  If it evaluates
to true then the code contained inside the following set of brackets
is executed.  For example...

if (condition_to_be_evaluated)
... if true this code executes ...

$x = 1
$y =1 

if ($x == $y)
print "Because X and Y are both equal to 1, the condition will
evaluate to true which means this code will be exacuted";

PASCAL looks a lot different (and a lot less clean if you ask me) when
it comes to if/then statements.  The basic structure of an if/then
statement in PASCAl is:

if BooleanExpression then
...this code gets evaluated

In the above example, the condition you want to test goes where
"BooleanExpression" is.  If this evaluates to true then the code
within the begin and end keywords gets executed.

*** Output ***
Outputting to the screen is very simple in both languages.  The
easiest way in PHP is to write:

print "What you want to output goes here";

In PASCAL the syntax goes as follows:

Writeln('What you want to output goes here');

*** For Loops ***
In PHP for loops look like this:

for (initial value x; condition for loop to finish; closing expression)

A practical example would be:

for ($x=0; $x<10; $x++)
print x;

This loop sets the initial value to x ($x=0) and then runs the code
print x; over and over until $x is greater then 10.  Each loop $x is
raised by 1.

On the Pascal side For loops take on this structure:

FOR var_name := initial_value TO final_value DO

...your code goes here...

----- Helpful Links -----
A number of helpful tutorials exist for both languages which will
further illustrate the syntax differences between the two.  If listed
a number of the best ones below.

*** PHP *** 

PHP - A Simple Tutorial

W3schools PHP Tutorial

PHP Tutorial Part 1

PHP Tutorial - Introduction

*** PASCAL ***

Learn Pascal Tutorial

Delphi and Pascal Programming Tutorial

Roby's Pascal Tutorial

I hope that this answered your questions.  If you need anything
cleared up, please request a clarification before rating my answer and
I will be more then happy to help.


Request for Answer Clarification by whitehat88-ga on 07 Jun 2005 10:53 PDT
Can you show me some more code difference using snippets?

Clarification of Answer by djbaker-ga on 07 Jun 2005 11:01 PDT
Sure.  What types of code snippets are you looking for, anything specific?

Request for Answer Clarification by whitehat88-ga on 12 Jun 2005 01:44 PDT
it would be good if a short program in pascal is translated into php,
let me know if it's possible :)

Clarification of Answer by djbaker-ga on 12 Jun 2005 10:05 PDT
Here is a very famous programming example called "The Towers of Hanoi".


(* The Towers Of Hanoi                                 *)
(* Pascal                                              *)
(* Copyright (C) 1998 Amit Singh. All Rights Reserved. *)
(*                       *)
(*                                                     *)
(* Tested under p2c and the GNU Pascal compiler        *)

PROGRAM Hanoi(input, output);

VAR N:integer;

PROCEDURE dohanoi(N, Tfrom, Tto, Tusing : integer);
    if N > 0 THEN
      dohanoi(N-1, Tfrom, Tusing, Tto);
      writeln('move ', Tfrom:1, ' --> ', Tto:1);
      dohanoi(N-1, Tusing, Tto, Tfrom);

  write('N = ? ');
  dohanoi(N, 1, 3, 2)



 * The Towers Of Hanoi
 * PHP
 * Copyright (C) 2001 Amit Singh. All Rights Reserved.


function PHP_printmove($from, $to)
    print "move $from ==> $to

function PHP_movedisk($from, $to, $using, $N)
    if ($N <= 1) {
        PHP_printmove($from, $to);
    } else {
        PHP_movedisk($from, $using, $to, $N - 1);
        PHP_printmove($from, $to);
        PHP_movedisk($using, $to, $from, $N - 1);

function PHP_hanoierror()

    print "You must specify the number of disks (maximum $HANOI_MAXDISKS) as an
 appropriate integer argument, for example:

 where  1 <= N <= $HANOI_MAXDISKS";

function PHP_hanoi($N)

    if (!ereg("^[0-9]+", $N) || ($N > $HANOI_MAXDISKS)) {
    } else {
        PHP_movedisk(1, 3, 2, $N);

    if ($argc != 1) {
    } else {
whitehat88-ga rated this answer:5 out of 5 stars and gave an additional tip of: $5.00
Very good, exactly what i expected!

There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy