StUdY GuiDe

Reference links

ReLaTeD

Other links

* Notes *

Using single vs. double quotation marks dictates whether the variable's 'name' or "value" is printed.


Escaping \n inside quotation marks will tell the browser to print a new line in the source code.
Escaping \r creates a carriage return.
Escaping \t inserts a tab.


Acceptable PHP commenting syntax:
Single line - // or #
Multiple line - /* */


An Array's key is also called its index.


Look-up a function in the PHP manual as www.php.net/function_name
Example: www.php.net/htmlspecialchars

Chapter One thru Three

In a Nutshell

PHP Version: 5.2.8


Main Content

<div id="floatRight">
<div id="mainContentHeader">
<h2>Chapter One thru Three</h2>
<p>In a Nutshell</p>
</div><!-- close #mainContentHeader -->

<div id="mainContent">

<div id="left">

<div id="banner">
<img src="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/images/phpftwww.png" height="521" width="23" alt="" />
</div><!--close #banner-->
</div><!--close #left-->

<div id="right">

<h2 class="first">Chapter One Exercise</h2>
<p>Double Quotes vs. Single Quotes</p>

<p>The following exercise is created by PHP using the back-slash to escape Double Quotes:<br />
<code><?php highlight_string('<?php print "<span class=\"indigo\">Hello World!</span>"; ?>'); ?></code><br />
<?php print "<span class=\"indigo\">Hello World!</span>"?></p>
<p>Single Quote method with no need to escape Double Quotes:<br />
<code><?php highlight_string('<?php print \'<span class="indigo">Hello World!</span>\'; ?>'); ?></code><br />
<?php print '<span class="indigo">Hello World!</span>'?></p>

<h2>Chapter Two Exercise</h2>
<p>Variables</p>

<p>Strings can hold a combination of letters, numbers, symbols, and spaces..<br />
Integers hold numbers.<br />
Arrays can hold integers and/or strings.</p>

<code>
<?php
highlight_string 
("<?php\n
\$first_name = Bonnie; // no quotes\n
\$last_name = \"Lincicome\"; // double quotes here\n
\t/* variables do not have to be quoted if\n
\tthere is one (no spaces) */\n
\$full_name = \"\$first_name \$last_name\"; /* together they\n
\tmust be double quoted */\n
print \"First Name is: \$first_name\"; /* to avoid errors,\n
\tstrings must be in double quotes\n
\tif they contain a variable */\n
print '<br />'; // single quotes here\n
print \"Last Name is: \$last_name\";\n
print '<br />';\n
print \"Full Name is: \$full_name\";\n
print \$full_name; // no need to add quotes with nothing added\n
print '\$full_name'; /* using single quotes will convert a\n
\t\"variable value\" to a 'variable name' */\n
?>"
?>
</code>

<p><?php
$first_name 
Bonnie;
$last_name "Lincicome";
$full_name "$first_name $last_name";
print 
"First Name is: $first_name";
print 
'<br />';
print 
"Last Name is: $last_name";
print 
'<br />';
print 
"Full Name is: $full_name";
print 
'<br />';
print 
$full_name;
print 
'<br />';
print 
'$full_name';
?>
</p>

<h2>Chapter Three Exercise</h2>
<p>A simple form.</p>

<p>
Registered Globals are turned off on this server.<br />
By enabling them, all you will need to do is add a $ to your name value<br />
(Example: $email) to print what was entered in that field.<br />
Below is the method that worked for me to retrieve and print data to the handle_form.php:
</p>

<code>
<?php
highlight_string 
("<?php\n
ini_set ('display_errors', 1); //show my errors\n
\t//This page receives the data from chapt. 1-3\n
\t/* It will receive: title, name, email, response,\n
\tcomments, and submit. */

print \"Thank you {\$_POST['title']} {\$_POST['name']}\n
for your comments. <br />\";\n
print htmlspecialchars(\"You stated that\n
you found this example to be\n
{\$_POST['response']} and added: {\$_POST['comments']}\");\n
\t/* the htmlspecialchars() function prevents users from\n
entering malicious code. */\n
?>"
)
?>
</code>

<form action="handle_form.php" method="post">
<fieldset>
  <table>  
    <tr>  
        <td>
            Mr. <input type="radio" name="title" value="Mr." />
            Mrs. <input type="radio" name="title" value="Mrs." />
            Ms. <input type="radio" name="title" value="Ms." />
        </td>
    </tr>
    <tr>
        <td>
            <label>Name:</label> <input class="tbl" type="text" name="name" />  
        </td>  
    </tr>  
    <tr>  
        <td>
            <label>Email Address:</label> <input class="tbl" type="text" name="email" />
        </td>
    </tr>
    <tr>
        <td>  
            <label>Response:</label><br />  
        </td>  
    </tr>  
    <tr>  
        <td>
            <select name="response">
                <option class="ex" value="excellent">This is excellent.</option>
                <option class="ok" value="okay">This is okay.</option>
                <option class="bor" value="boring">Okay, this is boring.</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>  
            <label>Comments:</label><br />
            <textarea name="comments" rows="3" cols="50"></textarea>  
        </td>  
    </tr>    
    <tr>
        <td>
            <input name="reset" type="reset" value="Reset" class="reset" />
        </td>
    </tr>
    <tr>
        <td>
            <input name="submit" type="submit" value="SuBmIt" class="submit" />
        </td>
    </tr>
  </table> 
  </fieldset>
  </form>

</div><!--close right-->

</div><!-- close #mainContent -->
</div><!--close #floatRight-->

Source Code for Current Page

<?php $page="one-three"?>

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

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Chapt. 1-3 Exercise</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link href="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/common/php.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrap">

<!-- Heading -->

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/h1.php'); ?>

<!-- Top Navigation Bar -->

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/bar-nav.php'); ?>

<!-- Related Links -->

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/h3.php'); ?>

<!-- Main Content -->

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/' $page '.php'); ?>

<!-- Bottom Navigation Bar -->

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/bar-nav2.php'); ?>

<!-- Foot -->

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/foot.php'); ?>
</div><!-- close #wrap -->

<!-- Show Source -->

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/source.php'); ?>
</body>

</html>


Head

<div id="head">
<p>Lzydaz.com</p>
<div id="heading">
<h1 id="top">PHP Study Group</h1>
<p>This page is designed as a study tool for the book<br />
<cite><a href="http://www.dmcinsights.com/phpvqs2">PHP for the World Wide Web by Larry Ullman (2nd Edition)</a></cite></p>
</div><!--close #heading-->
<img src="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/images/logo.png" height="67" width="100" alt="logo" />
</div><!-- close #head -->
<div id="head-edge">
<!--IE hates this-->
</div><!--close #head-edge-->

Navigation Bar

<div id="nav-top">
<?php $currentPage basename ($_SERVER['PHP_SELF']); ?>
<ul>
<li>
<a href="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/index.php" title="PHP Study Group Index"
<?php
if($currentPage=="index.php"){
    print 
'class="current"';
}
?>
    >Chapter Index</a><!--close anchor tag-->
    </li>
<li>
<a href="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/chapt1-3.php" title="Chapters One - Three"
<?php
if($currentPage=="chapt1-3.php"){
    print 
'class="current"';
}
?>
    >One - Three</a><!--close anchor tag-->
    </li>
    <li>
<a href="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/chapt4-6.php" title="Chapters Four - Six"
<?php
if($currentPage=="chapt4-6.php"){
    print 
'class="current"';
}
?>
    >Four - Six</a><!--close anchor tag-->
    </li>
    <li>
<a href="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/chapt7-9.php" title="Chapters Seven - Nine"
<?php
if($currentPage=="chapt7-9.php"){
    print 
'class="current"';
}
?>
    >Seven - Nine</a><!--close anchor tag-->
    </li>
    <li>
<a href="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/chapt10-13.php" title="Chapters Ten - Thirteen"
<?php
if($currentPage=="chapt10-13.php"){
    print 
'class="current"';
}
?>
    >Ten - Thirteen</a><!--close anchor tag-->
    </li>
    </ul>
    </div> <!-- close #nav-top -->

Related Links

<div id="floatLeft">
<div id="sideHeader1">
<h3>StUdY GuiDe</h3>
<p><em>Reference links</em></p>
</div><!-- close #sideHeader1 -->

<div id="side1">
<p><a href="http://www.php.net/manual" title="php.net">PHP Functions Manual</a></p>
</div><!-- close #side1 -->

<div id="sideHeader2">
<h3>ReLaTeD</h3>
<p><em>Other links</em></p>
</div><!-- close #sideHeader2 -->

<div id="side2">
<p><a href="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/phpBB3/index.php" title="Hello World">Forum</a></p>
<p><a href="http://rjoannej.com/ullmanBook/index.php" title="Joanne's Index">Joanne's Page</a></p>
<p><a href="http://krisse.tuna.fi/phpwww/index.php" title="Krisse's Index">Krisse's Page</a></p>
<p><a href="http://www.amaraland.com/studyGroup/index.php" title="KC's Index">KC's Page</a></p>

</div><!-- close #side2 -->

<div class="side3">

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/notes/note-' $page '.php'); ?>

</div><!--close #side3-->
</div><!--close #floatLeft-->

Foot

<div id="foot-edge">
<!--IE hates this-->
</div><!--close #foot-edge-->

<div id="foot">
<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/copyright.php'); ?>
<p><a href="http://validator.w3.org/check?uri=referer" rel="nofollow" title="XHTML Validator">XHTML</a> | <a href="http://jigsaw.w3.org/css-validator/check/referer" title="CSS Validator" rel="nofollow">CSS</a></p>
</div><!--close #foot-->

Copyright

<p>Bonnie Lincicome &copy; <?php echo date('Y');?> All Rights Reserved<br />
This page was last updated on <?php echo date('F d, Y H:i:s'getlastmod($filename)); ?></p>

Back to the Top