In class example

[article] [edit page] [discussion] [history]

From Humanitarian-FOSS Project Development Site

Return to Cpsc110/Notes/Starting PHP

<?php
/*
 * Created on Jan 27, 2008
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
?>
<HTML>
  <HEAD>
    <TITLE>Hello World</TITLE>
  </HEAD>
  <BODY>
    <?php
    // This is a comment.

    /*
     * This is multiline comment.
     */
    echo "<H2>This was printed by PHP.</H2>";
    $result = "20"/5;
    $result2 = 20/5;
    echo "\$result is $result<BR>";
    echo '\$result2 is  $result2<BR>';
    echo "\$result2 is  $result2<BR><BR>";


    // Define a function
	function birthday() {
   	global $age;
   	$age = 1;  // Set local variable age to 1
   	$age = $age + 1;
   	echo "In birthday() age is $age<br>";
	}
	birthday();
	$age = 30;   // Set age to 30
	birthday();  // Call the function
	echo "Outside age is $age<br>";   // This will print 30

	$name1 = "Bill";
	$name2 = "BIll";
	$result = strcasecmp($name1, $name2); // Compare but ignore case, returns 0
	echo "Comparing $name1 and $name2, ingoring case and result is $result<BR>";
	if (!$result) {
   	echo "They match, ignoring case<BR>";   // This will print in this case, because != 0
	}


	$result = strcmp($name1, $name2); // Compare but include case, returns non-zero
	echo "Comparing $name1 and $name2, including case and result is $result<BR>";
	if ($result) {
       echo "They don't match, including case";   // This will also print in this case b/c $result is non-zero
	}

    ?>
  </BODY>
</HTML>

Return to Cpsc110/Notes/Starting PHP

Personal tools