Ver Mensaje Individual
  #2  
Antiguo 03-11-2008
Avatar de enecumene
[enecumene] enecumene is offline
Miembro de Oro
 
Registrado: may 2006
Ubicación: Santo Domingo, Rep. Dom.
Posts: 3.040
Reputación: 24
enecumene Va por buen camino
Traté de implementar este código que conseguí aquí en el club:

Código PHP:
<?php // magic!

/*
    delphi2html PHP class v1.0b

    (w) 2005 David Esperalta Calderón

    Thanks very much to the people of ClubDelphi Forums
    ([url]http://www.clubdelphi.com[/url]) and specially to Román
    from the idea and tutorial. ¡Thanks to all! ;-)

    Comments are welcome in davidesperalta @ gmail.com
    or in the ClubDelphi Forums (see url above)

*/

/*
    // Example usage 1
    //
    $colorize = new delphi2html();
     $file = file('./delphi_unit.pas');
    foreach ($file as $line) $temp .= $line;
     echo $colorize->execute($temp, true, true);

*/

/*
    // Example usage 2
    //
    $colorize = new delphi2html();
    $text = "type\n";
    $text .= " TForm1 = class(TForm)\n";
    $text .= " { Private declarations }\n";
    $text .= " private\n";
    $text .= "    procedure AMethod(param: string);\n";
    $text .= " end;\n";
    echo $colorize->execute($text, true, true);

*/    

class delphi2html {

    
// Style (CSS code)
    //
    
var $css_style =
     
"<style type='text/css'>
         .str { background-color: transparent; color: Green; }
         .idn { background-color: transparent; color: Black; }
         .res { background-color: transparent; color: Navy; font-weight: bold; }
         .com { background-color: transparent; color: Gray; font-style: italic; }
     </style>\n"
;

    
// Reserved keywords in Delphi
    //
    
var $keybords = array (
     
"Piedra""Tijeras""Lápiz""Hoja"
    
);

    
// Regular Exp for strings, identifiers and comments tokens.
    //
    
var $reg_exp             "";
    var 
$reg_exp_strings     "('.*?')|";
    var 
$reg_exp_identifiers "([a-z_][a-z0-9_]*)|";
    var 
$reg_exp_comments    "(\{.*?\}|\(\*.*?\*\)|//.*?\n|//.*\$)";

    
// Class constructor.
    //
    
function delphi2html() {

        
$this->reg_exp "#".
         
$this->reg_exp_strings.
         
$this->reg_exp_identifiers.
         
$this->reg_exp_comments ."#si";
    }

    
// Callback function.
    //
    
function replace($matches) {

        switch (
$matches[0])
         {
            case 
$matches[1]: // strings
             
return "<span class='str'>" .$matches[1]. "</span>";
             break;

             case 
$matches[2]: // identifiers
                 
if (in_array($matches[2], $this->keybords))
                    return 
"<span class='res'>" .$matches[2]. "</span>";
                 else
                    return 
"<span class='idn'>" .$matches[2]. "</span>";
                 break;

             case 
$matches[3]: // comments
                 
return "<span class='com'>" .$matches[3]. "</span>";
                 break;
         }
    }

    
// The main public method: execute
    //
    // param: code, string: the delphi source code to colorize.
    // param: add_css_code, boolean: add the CSS code in result.
    // param: add_pre_tags, boolean: add the <pre></pre> HTML tags.
    //
    // return: HTML delphi colorized text.
    //
    
function execute($code$add_css_code true$add_pre_tags true) {

        
$result preg_replace_callback($this->reg_exp,
                    array(
$this'replace'), $code);
        
        if(!
$add_pre_tags) {
            
         if(!
$add_css_code) { return $result; }
         else { return 
$this->css_style $result; }            
        
        } else {
            
         if(!
$add_css_code) { return "<pre>" .$result"</pre>"; }
         else { return 
$this->css_style "<pre>" .$result"</pre>"; }
        
        }            
        
    } 
// function execute

// class delphi2html

?>
Mi código BBCode:

Código PHP:
<div class="post" id="msg_4"><div class="codeheader">Texto:</div><div class="code"><pre style="margin-top: 0; display: inline;"><?php $colorize = new delphi2html();
     echo 
$colorize->execute({content}, truetrue); ?></div>
¿Problema?:

Cita:
Fatal error: Cannot redeclare class delphi2html in C:\AppServ\www\smf\Sources\Delphi.php on line 41
lo que hice fue, grabé ese código en un archivo Texto.php, y lo incluí en el php donde se usa los tags.

¿A qué se debe ese error?.

Saludos.
__________________

Mi BLOG - ¡Joder, leanse la guia de estilo!
Las Palabras son enanas, los ejemplos gigantes.
Responder Con Cita