Variables illustration


The current date and time is September 7th, 2010 8:50:AM

Companion Web Site

Larry Ullman has a web site devoted to PHP for the World Wide Web: Second Edition at this location.

It is intended as a supplement /complement to the book and has many helpful resources.

The Book

Variable image

PHP for the World Wide Web: Second Edition written by Larry Ullman

Chapter 5
Using Strings

About Strings

This chapter dealt with trimming, joining and encoding strings. Remembering that a variable is a container for data and that strings are the most common type of variable, we begin using strings in form responses. Strings are containers of characters, meaning anything from a single letter, code, words, numbers, nonsense to symbols and so on! A string will be printed out in the case of form responses as names, email addresses and the sentences that the user types into the text area. String functions will change the way the output (printed data) will be presented.

The handle_post file went through many alterations, all having to do with string functions, including one which will catch bad words (if you use whatever bad words you want or think possible instead of the generic badword)! If you type 'badword' into the posting below, the string_replace() function will replace it with xxxxx in the handle_post page.

The Form

Complete and submit your posting

First Name:
Last name:
Email Address:
Posting:

Magic Quotes

I now know that Magic Quotes are enabled on my server and so I will need to use the stripslashes() function. I finally understand the reasoning why! Look at this and notice the slashes in the reply. It is because I experimented using " " in my reply. Also applies to '. Need stripslashes??
So, back to the form and put in the stripslashes() function... but now, I know why! I remember doing this when Krisse and I were in the first PHP 101 and I didn't know why! It is good to know why!

 


<?php 
/* My Variables for the study group site */
$book "<u>PHP for the World Wide Web: Second Edition</u>";
$author "Larry Ullman";
$myName "Joanne Johnson";
$pageTitle "PHP Study Group ";

?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $pageTitle ?></title>

<link href="common/ullman.css" rel="stylesheet" type="text/css" />
<link href="../SpryAssets/ullmanMenu.css" rel="stylesheet" type="text/css" />
<script src="../SpryAssets/SpryMenuBar.js" type="text/javascript"></script>



<!--[if IE 7]><link rel="stylesheet" href="common/fieldsetStyleIe.css" 
type="text/css" /><![endif]-->
<link href="common/form5.css" rel="stylesheet" type="text/css" />
</head>

<body class="thrColHybHdr">

<div id="container">
  <div id="header">
    <h1><?php echo $pageTitle ?></h1>
    <p>Presented by <?php echo $myName ?><br />
    Started January, 2009<br />
    </p>
    <br />
  <!-- end #header --></div>
  <div id="sidebar1">
    <div align="center">
      <?php include("includes/nav.php"); ?>
    <img src="images/var.jpg" 
    alt="Variables illustration" width="140" height="373" />
      <br />
      <br />    
      <br />
      
    </div>
    <p>The current date and time is <?php echo date ("F jS, Y g:i:A");?></p>
  <!-- end #sidebar1 --></div>
  <div id="sidebar2">
    <h3>Companion Web Site</h3>
    <p>Larry Ullman has a web site devoted to <?php echo $book ?> at this 
    <a href="http://www.dmcinsights.com/phpvqs2/" target="_blank">location</a>.</p>
    <p>It is intended as a supplement /complement to the book and has many 
    helpful resources.</p>
    <ul>
      <li><a href="http://www.dmcinsights.com/phpvqs2/errata.php">Errata</a></li>
      <li><a href="http://www.dmcinsights.com/phorum/list.php?10" target="_blank">Forum</a></li>
      <li><a href="http://blog.dmcinsights.com/" target="_blank">L. Ullman Blog</a></li>
      <li><a href="http://www.dmcinsights.com/bk_pages/faq.php?i=phpvqs2" target="_parent">FAQ</a></li>
      <li><a href="http://de.php.net/manual/en/manual.php" target="_blank">PHP Manual</a></li>
    </ul>
    <p><img src="images/book.jpg" alt="The Book" width="163" height="203" /></p>
    
    <div align="center"><img src="images/var.jpg" alt="Variable image" width="150" height="400" />
      </div>
  <!-- end #sidebar2 --></div>
  <div id="mainContent">
  <center><h3><?php echo $book ?> <span class="spanTitle" >written by</span> 
  <?php echo $author ?></h3></center>
    <h2 align="center">Chapter 5<br />
      Using Strings</h2>
    <p><strong>About Strings</strong></p>
    <ul>
      <li>Creating the HTML Form</li>
      <li>Connecting Strings (Concatenation)</li>
      <li>Combating Magic Quotes</li>
      <li>HTML and PHP</li>
      <li>Encoding and Decoding Strings</li>
      <li>Replacing Parts of a String</li>
      <li>Other String Functions</li>
    </ul>
    <p>This chapter dealt with trimming, joining and encoding strings. Remembering that a variable is a 
    container for data and that strings are the most common type of variable, we begin using strings 
    in form responses. Strings are  containers of characters, meaning anything  from a single letter, code, words, numbers, 
    nonsense to symbols and so on! A string will be printed out in the case of form responses as names, 
    email addresses and the sentences that the user types into the text area. String functions will change 
    the way the output (printed data) will be presented.</p>
    <p>The handle_post file went through many alterations, all having to do with string functions, including 
    one which will catch bad words (if you use whatever bad words you want or think possible instead 
    of the generic badword)! If you type 'badword' into the posting below, the string_replace() function will 
    replace it with xxxxx in the handle_post page.</p>
    <h3 align="left">The Form</h3>
    <div id="formDiv">
      <p><strong> Complete and submit your posting</strong>      </p>
      <form action="handle_post.php" method="post">
        First Name: <input  type="text" name="first_name" size = "20" />
        <br />
        Last name:  <input type="text" name="last_name" size = "20" />
        <br />
        Email Address: <input type="text" name="email" size = "20" />
        <br />
        Posting: 
        <textarea name="posting" rows ="3" cols="30"></textarea>
        <input class="button" type="submit" name="submit" value="Send My Posting"/>
      </form>
    </div>
    <p><strong>Magic Quotes</strong></p>
    <p>I now know that Magic Quotes are enabled on my server and so I will need to use the stripslashes() function. 
    I finally understand the reasoning why! Look at this and notice the slashes in the reply. It is because 
    I experimented using &quot; &quot; in my reply. Also applies to '. <a href="images/magQuotes.jpg">
      Need stripslashes??</a> <br />
      So, back to the form and put in the stripslashes() function...
    but now, I know why! I remember doing this when Krisse and I were in the first PHP 101 and I didn't know why! 
    It is good to know why!</p>
    <p>&nbsp;</p>
    <p><br class="clearfloat" />
    </p>
  </div>
  <div id="footer">
    <p align="center">&copy;R. Joanne Johnson 2009 </p>
    <p align="center"><a href="http://validator.w3.org/check?uri=referer" 
    target="_blank"><img
        src="http://www.w3.org/Icons/valid-xhtml10"
        alt="Valid XHTML 1.0 Transitional" width="88" height="31" border="0" /></a></p>
  <!-- end #footer --></div>
<!-- end #container --></div>
 
<div id="sourceDiv">
   <?php  
   
/* shows the source code of the page */
   
show_source(basename($_SERVER['PHP_SELF'])); ?>
    
  <?php  
   
/* shows source for nav bar include */
  
show_source("includes/nav.php");?>
</div>


</body>
</html>
<ul id="MenuBar1" class="MenuBarVertical">
          <li><a href="/ullmanBook/chapter1.php">Chapter 1</a></li>
      <li><a href="/ullmanBook/chapter2.php">Chapter 2</a></li>
  <li><a href="/ullmanBook/chapter3.php">Chapter 3</a> </li>
  <li><a href="/ullmanBook/chapter4.php">Chapter 4</a></li>
  <li><a href="/ullmanBook/chapter5.php">Chapter 5</a></li>
  <li><a href="/ullmanBook/chapter6.php">Chapter 6</a></li>
      <li><a href="/ullmanBook/chapter7.php">Chapter 7</a></li>
  <li><a href="#">Chapter 8</a></li>
      <li><a href="#">Chapter 9</a></li>
      <li><a href="#">Chapter 10</a></li>
      <li><a href="#">Chapter 11</a></li>
      <li><a href="#">Chapter 12</a></li>
      <li><a href="#">Chapter 13</a></li>
      <li><a href="/ullmanBook/index.php">Home</a></li>
       <li><a href="http://www.lzydaz.com/phpBB3/index.php" target="_blank">Hello World</a></li>
       <li><a href="http://www.lzydaz.com/studygroup/php/index.php" target="_blank">Bonnie</a></li>
       <li><a href="http://www.amaraland.com/studyGroup/index.php" target="_blank">Kc Ladybug</a></li>
       <li><a href="http://krisse.tuna.fi/phpwww/ch1.php" target="_blank">Krisse</a></li>
       
       
    </ul>