PHP Lab #2: Built-in functions

  1. Somewhere inside the PHP code in hello.php, add the statements:

    print(phpversion());
    print("<BR>");
    (Don't forget the semicolon.)

  2. Reload the web page, and answer the following questions:

  3. Now change your hello.php so that phpversion() is in quotes, so that it looks like:

    print("phpversion()");
  4. Answer the following question:
  5. Somewhere inside the PHP code in hello.php, add the statements:

    print(date("m.d.y"));
    print("<BR>");
    Observe what happens.

  6. Open a new browser window (File, New Window) and go to the web site www.php.net. In the "search for" box near the top right hand corner, enter "date" and click on the right arrow on the right side of the screen. You can get instructions for any PHP function this way.

  7. Within the php.net instructions for date, scroll down until you see Example 4, which is titled "date() Formatting". Study this example, then change your PHP code to display the date and time in the formats "9:45 AM, 1 October 2001" and "Monday, Oct 1, 2001, at 9:45 AM". Answer the following question:

  8. The php function "number_format" is used to print out numbers in different styles. Somewhere inside the PHP code in hello.php, add the statements:

    print(number_format("12345678","2"));
    print("<BR>");
    Observe what happens.

  9. Take out the second argument inside number_format.

  10. Put the second argument back in, but change the first argument to "12345678.452".

  11. Use "Q" and "Z" for the third and fourth arguments.

  12. In France, they would write "1.234,56" instead of "1,234.56". Experiment with number_format to write your numbers in the French way.

  13. Use just three parameters. Answer the following question:


Page by Michelle Phillips, Jeff Ondich, and Dave Musicant. Last updated 10.03.02