PEAR Articles

  Home arrow PEAR Articles arrow Page 2 - PEAR: an Introduction
PEAR ARTICLES

PEAR: an Introduction
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2010-07-21

    Table of Contents:
  • PEAR: an Introduction
  • The Power of PEAR: Converting Numeral Formats
  • Installing and Updating PEAR
  • Updating PEAR

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    PEAR: an Introduction - The Power of PEAR: Converting Numeral Formats


    (Page 2 of 4 )

     

    The power of PEAR is best demonstrated with a specific example. In particular, we call attention to a package that exemplifies why you should regularly look to the repository before attempting to resolve any significant programming task.

    Suppose you were recently hired to create a new Web site for a movie producer. As we all know, any serious producer uses Roman numerals to represent years, and the product manager tells you that any date on the Web site must appear in this format. Take a moment to think about this requirement because fulfilling it isn’t as easy as it may sound. Of course, you could look up a conversion table online and hard-code the values, but how would you ensure that the site copyright year in the page footer is always up to date? You’re just about to settle in for a long evening of coding when you pause for a moment to consider whether somebody else has encountered a similar problem. “No way,” you mutter, but taking a quick moment to search PEAR certainly would be worth the trouble. You navigate over and, sure enough, encounterNumbers_Roman.

    For the purpose of this exercise, assume that theNumbers_Romanpackage has been installed on the server. Don’t worry too much about this right now because you’ll learn how to install packages in the next section. So how would you go about making sure the current year is displayed in the footer? By using the following script:

    <?php

       // Make the Numbers_Roman package available
      
    require_once("Numbers/Roman.php");

       // Retrieve current year
      
    $year = date("Y");

       // Convert year to Roman numerals
      
    $romanyear = Numbers_Roman::toNumeral($year);

       // Output the copyright statement
      
    echo "Copyright &copy; $romanyear";
    ?>

    For the year 2007, this script would produce the following:

    --------------------------------------------
    Copyright © MMVII
    --------------------------------------------

    The moral of this story? Even though you may think that a particular problem is obscure, other programmers likely have faced a similar problem, and if you’re fortunate enough, a solution is readily available and yours for the taking.

    More PEAR Articles Articles
    More By Apress Publishing

    blog comments powered by Disqus

    PEAR ARTICLES ARTICLES

    - Installing PEAR
    - PEAR: an Introduction
    - Managing robots.txt using PHP: Generating Dy...
    - Deleting Authors from a PEAR Content Managem...
    - PEAR CMS: Index and Delete Scripts
    - Listing Articles for a PEAR Content Manageme...
    - Building an Authors Page for a PEAR CMS
    - Building the View Details Page in a PEAR CMS
    - Creating the Main Pages of a PEAR CMS
    - Completing the Login Script for a PEAR CMS
    - User Authentication for a PEAR CMS
    - A PEAR CMS: Examining the Code
    - Building a Content Management System with PE...
    - Installing a PEAR Package
    - My PEAR: The Beginning


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap