Você está na página 1de 9

PHP Program Source Code (22/02/2010)

(phptags.php)
<?php
echo "<P>This is a test using the first tag type.</P>";
?>

<?
echo "<P>This is a test using the second tag type.</P>";
?>

<script language="php">
echo "<P>This is a test using the third tag type.</P>";
</script>

(firstscript.php)
<HTML>
<HEAD>
<TITLE>My First PHP Script</TITLE>
</HEAD>
<BODY>

<?
echo "<P><em>Hello World! I'm using PHP!</em></P>";
?>

</BODY>
</HTML>
(errorscript-a.php)
<HTML>
<HEAD>
<TITLE>Trying For Another Error</TITLE>
</HEAD>
<BODY>
<?
echo "<P>I am trying to produce an error</P>"
echo "<P>Was I successful?</p>";
?>
</BODY>
</HTML>

(errorscript-b.php)
<HTML>
<HEAD>
<TITLE>Trying For Another Error</TITLE>
</HEAD>
<BODY>

<?
echo "<P>I am trying to produce an error</P>";
echo "<P>Was I successful?</p>";
?>

</BODY>
</HTML>
(errorscript2-a.php)
<HTML>
<HEAD>
<TITLE>Trying For Another Error</TITLE>
</HEAD>
<BODY>

<?
echo "<P>I think this is really "cool"!</p>";
?>

</BODY>
</HTML>

(errorscript2-b.php)
<HTML>
<HEAD>
<TITLE>Trying For Another Error</TITLE>
</HEAD>
<BODY>

<?
echo "<P>I think this is really \"cool\"!</p>";
?>

</BODY>
</HTML>
(comments.php)
<HTML>
<HEAD>
<TITLE>Code Comments</TITLE>
</HEAD>
<BODY>

<!-- This is an HTML comment. -->

<?

// This is a simple PHP comment.

/* This is a C-style, multi-line comment. You can make this as


long as you'd like. */

# Used to shells? Use this kind of comment.

?>

(printvarscript.php)
<HTML>
<HEAD>
<TITLE>Printing Variables</TITLE>
</HEAD>
<BODY>

<?
$intVar = "9554215464";
$floatVar = "1542.2232235";
$stringVar = "This is a string.";

echo "<P>integer: $intVar</p>";


echo "<P>float: $floatVar</p>";
echo "<P>string: $stringVar</p>";
?>
</BODY>
</HTML>

(phpinfo.php)
<? phpinfo(); ?>

(constants.php)
<?
define("MYCONSTANT","This is a test of defining constants.");
echo MYCONSTANT;
?>

(constants2.php)
<?
echo "<br>This file is ".__FILE__;

echo "<br>This is line number ".__LINE__;

echo "<br>I am using ".PHP_VERSION;

echo "<br>This test is being run on ".PHP_OS;


?>
(assignscript.php )
<HTML>
<HEAD>
<TITLE>Using Assignment Operators</TITLE>
</HEAD>
<BODY>

<?
$origVar = 100;
echo "<P>Original value is $origVar</p>";

$origVar += 25;
echo "<P>Added a value, now it's $origVar</p>";

$origVar -= 12;
echo "<P>Subtracted a value, now it's $origVar</p>";

$origVar .= " chickens";


echo "<P>Final answer: $origVar</p>";
?>
</BODY>
</HTML>

(arithmeticscript.php)
<HTML>
<HEAD>
<TITLE>Using Arithmetic Operators</TITLE>
</HEAD>
<BODY>

<?
$a = 85;
$b = 24;
echo "<P>Original value of \$a is $a and \$b is $b</p>";
$c = $a + $b;
echo "<P>Added \$a and \$b and got $c</p>";

$c = $a - $b;
echo "<P>Subtracted \$b from \$a and got $c</p>";

$c = $a * $b;
echo "<P>Multiplied \$a and \$b and got $c</p>";

$c = $a / $b;
echo "<P>Divided \$a by \$b and got $c</p>";

$c = $a % $b;
echo "<P>The modulus of \$a and \$b is $c</p>";
?>

</BODY>
</HTML>

comparisonscript.php
<HTML>
<HEAD>
<TITLE>Using Comparison Operators</TITLE>
</HEAD>
<BODY>

<?
$a = 21;
$b = 15;
echo "<P>Original value of \$a is $a and \$b is $b</p>";

if ($a == $b) {
echo "<P>TEST 1: \$a equals \$b</p>";
} else {
echo "<P>TEST 1: \$a is not equal to \$b</p>";
}

if ($a != $b) {
echo "<P>TEST 2: \$a is not equal to \$b</p>";
} else {
echo "<P>TEST 2: \$a is equal to \$b</p>";
}

if ($a > $b) {


echo "<P>TEST 3: \$a is greater than \$b</p>";
} else {
echo "<P>TEST 3: \$a is not greater than \$b</p>";
}

if ($a < $b) {


echo "<P>TEST 4: \$a is less than \$b</p>";
} else {
echo "<P>TEST 4: \$a is not less than \$b</p>";
}

if ($a >= $b) {


echo "<P>TEST 5: \$a is greater than or equal to \$b</p>";
} else {
echo "<P>TEST 5: \$a is not greater than or equal to \$b</p>";
}

if ($a <= $b) {


echo "<P>TEST 6: \$a is less than or equal to \$b</p>";
} else {
echo "<P>TEST 6: \$a is not less than or equal to \$b</p>";
}
?>
</BODY>
</HTML>

logicalscript.php
<HTML>
<HEAD>
<TITLE>Using Logical Operators</TITLE>
</HEAD>
<BODY>

<?
$degrees = "95";
$hot = "yes";

if (($degrees > 100) || ($hot == "yes")) {


echo "<P>TEST 1: It's <strong>really</strong> hot!</p>";
} else {
echo "<P>TEST 1:It's bearable.</p>";
}

if (($degrees > 100) && ($hot == "yes")) {


echo "<P>TEST 2: It's <strong>really</strong> hot!</p>";
} else {
echo "<P> TEST 2: It's bearable.</p>";
}

?>
</BODY>
</HTML>

Você também pode gostar