Oppure

Loading
20/02/12 15:47
Sevenjeak
Premetto di sapere che on-line esistono già delle classe che effettuano il parsing del codice BB, ma non penso che facciano ciò che io voglia, se mai, non so, potrete suggerirmela una voi.

Cmq ho da poco creato questa classe, per interpretare in BBCode presente in una stringa, anche se ancora non completa del tutto:

<?php
class BBCode
{
   var $output = null;
   var $sh = null;
   var $rp = null;
   
   function __construct($args)
   {
      $args = func_get_args();
      $this->sh = array();
      $this->rp = array();
      
      for ($i = 0; $i < count($args); $i++) 
      {
         $tag = $args[$i];
         
         switch ($tag) {
            case "b" || "i" || "u" || "code":
               $this->sh[] = "/[$tag\](.*?)\[\/$tag\]/";
               $this->rp[] = "<$tag>\1</$tag>";
            break;
         }
      }
   }
   
   function parsing($text) 
   {
      str_replace("<", "&lt;", $text);
       str_replace(">", "&lt;", $text);
      preg_replace($this->sh, $this->rp, $text);

      $this->output = $text;
   }

   function out()
   {
      echo $this->output;
   }
}
?>


In poche parole, il costruttore accetta vari parametri ( nel mio caso i tag BB che dovrebbe interpretale ), dopo richiamando la funzione parsing(), che come parametro accetta la stringa contenente il codice BB da interpretare, mi dovrebbe interpretarlo, ma non fa ciò che io vorrei, visto che la funzione out(), che restituisce il testo dopo l'interpretazione del codice BB, mi restituisce il testo senza il codice interpretato.

Come potrei risolvere, dove sbaglio? non so se sono stato abbastanza chiaro.
Ultima modifica effettuata da Sevenjeak 20/02/12 15:52
aaa