O'Reilly logo

Ajax Bible by Steven Holzner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13

PHP: Functions and HTML Controls

IN THIS CHAPTER

  • Creating functions
  • Passing data to functions
  • Creating default arguments
  • Creating variable-length argument lists
  • Returning data from functions
  • Returning multiple items from a function
  • Working with text fields, checkboxes, and radio buttons
  • Handling multiple-selection HTML controls
  • Uploading files

This chapter continues your guided tour of PHP with handling PHP functions and HTML controls. PHP functions are just as important in PHP as in JavaScript, but there's some added power in PHP compared to JavaScript. And working with HTML controls is the whole main point of using server-side scripting for many developers. You're going to see both in this chapter.

images For an introduction to using PHP with Ajax, see Chapter 12.

Working with Functions

On the face of it, functions work much the same in PHP as in JavaScript. Here's how a function is set up:

function function_name([argument_list…])
{
    [statements;]
    [return return_value;]
}

It's easiest to see this with examples. For instance, you might want to use a function to display a copyright symbol at the bottom of your Web pages. You would start by displaying the Web page content like this:

<html>
  <head>
    <title>Using functions to create a copyright
mark</title>
  </head>
  <body>
    <h1>Using functions to create a copyright mark</h1>

    <?
      echo “<h3>Welcome to my web page!</h3>”;
      echo ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required