PHP: Control Statements, Functions, Regex Patterns, Forms




CS174

Chris Pollett

Feb 24, 2016

Outline

Control Statements

On Monday, we started introducing the PHP language. We learned a little about its history and configuration. We also learned about its copy and interpretive mode, its types, literals, operators, and outputing mechanisms. Today, we start by looking at some of its control structures.

Arrays

More on PHP Arrays

Yet More on PHP Arrays

Iterating Through Arrays

Functions

Variable Scope

Pattern Matching

Types of web forms

Built-in Globals

Let's Build Something

  • Create a PHP script, message.php which would live under your web server's document root, and would be run when you visited the url in your browser corresponding to http://your-websvers-url/message.php.
  • This script initially outputs a form with a labeled text field and a submit button. The label says: "Enter your message here:".
  • When a user submits the form, it outputs a page with heading "Words Seen". Beneath this it outputs each word seen in the submitted text field data, each in a separate div tag.
  • Beneath this it has a link back to the form page.
  • Your code should use the following template code and is not allowed to output anything or have any control while in the global scope.
    <?php
    function messageController()
    {
       //decide which view to use and set up data for output
    }
    function formView($data)
    {
       // $data has any data set up from the controller
       //outputs the message form
    }
    function seenWordsView($data)
    {
       //outputs seen words, allowed a foreach loop and to
       //echo variables. Not allowed to call preg_ functions or explode
    }
    messageController();
    
  • Post your solution to the Feb 24 Class Thread.