SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Volitics's Avatar
    Join Date
    Aug 2003
    Location
    US
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Will Larry Ullman's HtmlTemplate class work with PHP 5?

    Hello.

    I got the class below out of a book written by Larry Ullman entitled "PHP Advanced For the World Wide Web." I think that the class is a commonly-used class.

    I was wondering if somebody might be familiar with the class.

    It works fine on my server hosting. I've just got a shared hosting. It's running PHP Version 4.3.11. The PHP Info page says the build date was Apr 7 2005. I've had the hosting for several months. It looks like the hosting provider, GoDaddy, has periodically updated the version of PHP.

    I've read that some of the functionality for PHP 4 will not work with PHP 5. I'm a little bit worried that GoDaddy may upgrade to PHP 5 without notification.

    My question is this: Will the class below work with PHP 5? In other words, if the hosting service provider upgrades to PHP 5 will I have to get another Html class rather than use the one below?

    PHP Code:
    // This page calls the class, the template, and instantiates the object.
    require_once "HtmlTemplateClass.php";
    $Page = new HtmlTemplate(); // call the template.
    $Page->IdentifyTemplate ("./templates/Template.html"); // identify the template.
    // then, call the functions.
    $Page->SetParameter "CURRENT_DATE""this is the date<br>" );
    $Page->SetParameter "MEMBERSHIP_TYPE""membership type here.<br>" ); 
    $Page->SetParameter "PAYMENT_TYPE""the payment goes here.<br>" );
    $Page->SetParameter "BUSINESS_CATEGORY""finally, this is the category" );
    $Page->CreatePage();

    // --------- HtmlTemplate class ------
    class HtmlTemplate {

        
    // Set the attributes.
        
    var $Template;
        var 
    $Html;
        var 
    $Parameters = array();

        function 
    IdentifyTemplate ($Template) { // This function sets which template will be used.
            
    $this->Template $Template;
        }

        function 
    SetParameter ($Variable$Value) { // This function sets the particular values.
            
    $this->Parameters[$Variable] = $Value;
        }

        function 
    CreatePage () { // This function does the bulk of the work.
            
    $this->Html implode ("", (file($this->Template))); // Read the template into an array, then create a string.

            
    foreach ($this->Parameters as $Key => $Value) { // Loop through all the parameters and set the variables to values.
                
    $TemplateName '{'.$Key.'}';
                
    $this->Html str_replace ($TemplateName$Value$this->Html);
            }    
            echo 
    $this->Html;
        }
    }
        

    // ----- Template.html ------
    // Outputs the information on the page.
    <html>
    <
    body leftmargin="100" topmargin="150">
    {
    CURRENT_DATE}
    {
    MEMBERSHIP_TYPE}
    {
    PAYMENT_TYPE}
    {
    BUSINESS_CATEGORY}
    </
    body>
    </
    html
    Thanks.

  2. #2
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should work, I think.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •