Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Template tramite PHP

  1. #1

    Template tramite PHP

    Ciao a tutti sto seguendo la seguente guida , secondo me non è fatta benissimo.

    Sto avendo qualche problema in quanto il risultato finale non è ottimale anzi è pari a zero
    Il codice utilizzato è praticamente lo stesso ovvero :
    classe :
    Codice PHP:
    <?php
    class sysTemplate
    {
      var 
    $template;

      function 
    sysTemplate($ts=array(),$cache='d_cache.txt',$sec=3600,$tpl='tpl.html')
      {
        if(!
    $this->template=$this->r($cache,$sec))
        {
          (@
    file_exists($tpl))?$this->template=@file_get_contents($tpl):die('
          Attenzione: Il file '
    .$tpl.' non è presente');
          
    $this->parserT($ts,$cache);
        }
      }

      function 
    parserT($ts,$cache)
      {
        if(@
    count($ts)>0)
        {
          foreach(
    $ts as $t=>$d)
          {
            
    $d=(@file_exists($d))?$this->getFile($d):$d;
            
    $this->template=@str_replace('{'.$t.'}',$d,$this->template);
          }
          
    $this->buildCache($cache,$this->template);
        }else{
          die(
    'Attenzione: impossibile eseguire il replace dei tags.');
        }
      }

      function 
    getFile($doc)
      {
        @
    ob_start();
        include(
    $doc);
        
    $contenuto=@ob_get_contents();
        @
    ob_end_clean();
        return 
    $contenuto;
      }

      function 
    buildCache($cache,$contenuto)
      {
        
    $f=@fopen($cache,'w');
        @
    fwrite($f,$contenuto);
        @
    fclose($f);
      }

      function 
    r($cache,$sec)
      {
        if(@
    file_exists($cache)&&@filemtime($cache)>(@time()-$sec))
        {
          return @
    file_get_contents($cache);
        }
        return 
    false;
      }
       
      function 
    show()
      {
        return 
    $this->template;
      }
    }
    ?>
    File per output
    Codice PHP:
    <?php
    require_once 'class.templates.php';

    $ts = array('titolo'=>'Quello che preferite..',
    'header'=>'Il nome del sito o il logo..',
    'menu'=>'item1 item 2',
    'colsx'=>'Un pò di headlines..',
    'mainbox'=>'Il testo di un articolo..',
    'coldx'=>'Spot pubblicitari..',
    'footer'=>'Disclamer e contatti..');

    $temp = @new sysTemplate($ts,'filecache.txt',10,'tpl.html');
    echo 
    $temp->show();
    ?>
    dentro tpl.html ho il seguente codice
    codice:
    <html>
    <head>
    <title>{titolo}</title>
    ....
    Apposto di {titolo} dovrei vedere -> Quello che preferite ma nulla vedo la variabile perchèèè???

  2. #2

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.