CSci 1101: First php examples.

The very first php example


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- 
The very first php example
Author: Elena Machkasova elenam@morris.umn.edu 
Last modified: 2/13/08
--> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>
<?php print "First PHP example\n";?>
</title>
</head>
<body>
<h1>

<?php print "First PHP example\n";?>
</h1>

<p>Today we start learning PHP. </p>
</body>
</html>
http://csci1101sp10.morris.umn.edu/~elenam/1101_spring10/first/first.php

A simple php example with a variable


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- 
A simple php example with a variable
Author: Elena Machkasova elenam@morris.umn.edu 
Last modified: 2/6/07 
-->
<?php 
$pagename = "Second PHP example\n"; 
?> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

<title>
<?php print $pagename;?>
</title>
</head>
<body>

<h1>
<?php print $pagename;?>
</h1>

<p>Today we start learning PHP. </p>
</body>
</html>
http://csci1101sp10.morris.umn.edu/~elenam/1101_spring10/first/second.php

A php example with several variables


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- 
A php example with several variables
Author: Elena Machkasova elenam@morris.umn.edu 
Last modified: 2/6/07 
-->
<?php 
$pagename = "Another PHP example";
$username = "Mary";
$the_color = "#00FF00";
?> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>

<?php print $pagename?>
</title>

</head>
<body>
<h1>
<?php print $pagename;?>
</h1>
<p>
<? print $username?>, welcome to this page! 

</p>
<p style="font-weight: bold; color: <? print $the_color?>">

Isn't it really cool?
</p>
</body>
</html>
http://csci1101sp10.morris.umn.edu/~elenam/1101_spring10/first/third.php

A list example


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- 
A list example 
Author: Elena Machkasova elenam@morris.umn.edu 
Last modified: 2/6/07 
-->
<?php 
/* comments */
$num_style="upper-roman";
$start_number=3;
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
<title>

PHP list numbering example
</title>
</head>

<body>
<ol style="list-style-type: <? print $num_style ?>" start="<? print $start_number?>">
<li>List element</li>

<li>Another list element</li>

<li>And another one</li>
</ol>
</body>
</html>
http://csci1101sp10.morris.umn.edu/~elenam/1101_spring10/first/list.php

More on php variables


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Examples of PHP variables and their use
Author: Elena Machkasova elenam@morris.umn.edu
Last modified: 9/24/06
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
<title>
Examples of PHP variables and their use

</title>
</head>

<body>
<h2>This page tests PHP variables</h2>
<p>
<?php
	       // integers and what you can do with them
$n = 2;
$m = 3;
$sum = $n + $m;

// variables are a part of the string that gets printed
print "$n + $m = $sum<br/>\n";

$prod = $n * $m;
$div = $n / $m;
$remainder = $n % $m;
print "$n * $m = $prod<br/>\n $n / $m = $div<br/>\n $n % $m = $remainder<br/>\n";

// changing $n:
$n = $m + 1;
// using \ to print $
print "\$n = $n<br/>\n";
?>

</p>
</body>
</html>
http://csci1101sp10.morris.umn.edu/~elenam/1101_spring10/first/variables.php

This page is a part of CSci 1101 course web site.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.