Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/07/2006, 17:05
Avatar de FuLaNo_
FuLaNo_
 
Fecha de Ingreso: mayo-2003
Ubicación: Don Torcuato, Buenos Aires, Argentina
Mensajes: 1.250
Antigüedad: 21 años
Puntos: 2
Alguien podría hacer de esta funcion una clase?

Hola gente!

Realmente nunca programe una clase y viendo algunas hechas realmente no le encuentro la vuelta, mi idea es que si alguien podría pasar una funcion bbcode que tengo yo a clase, y alli ver la diferencia para luego entender mejor la teoria...

Mi funcion es esta:

Código PHP:
<?php
  
function BBcode($texto) {
    
// Negritas [b]texto[/b]
    
$texto preg_replace("`\[b\](.*?)\[/b\]`is"'<span class="font_bold">$1</span>'$texto);
    
// Italicas [i]texto[/i]
    
$texto preg_replace("`\[i\](.*?)\[/i\]`is"'<span class="font_italic">$1</span>'$texto);
    
// Subrayadas [u]texto[/u]
    
$texto preg_replace("`\[u\](.*?)\[/u\]`is"'<span class="font_unde">$1</span>'$texto);
    
// Tachadas [t]texto[/t]
    
$texto preg_replace("`\[t\](.*?)\[/t\]`is"'<span class="font_tach">$1</span>'$texto);
    
// Texto centrado [center]texto[/center]
    
$texto preg_replace("`\[center\](.*?)\[/center\]`is"'<p class="center">$1</p>'$texto);
    
// Texto izquierda [left]texto[/left]
    
$texto preg_replace("`\[left\](.*?)\[/left\]`is"'<p class="left">$1</p>'$texto);
    
// Texto derecha [right]texto[/right]
    
$texto preg_replace("`\[right\](.*?)\[/right\]`is"'<p class="right">$1</p>'$texto);
    
// Texto justificado [justify]texto[/justify]
    
$texto preg_replace("`\[justify\](.*?)\[/justify\]`is"'<p class="justify">$1</p>'$texto);
    
// Texto justificado [justify]texto[/justify]
    
$texto preg_replace("`\[color=(green|red|black|blue|violet|orange|graydark|graylight|cyan|olive|yellow|bluelight|bluedark|pink|greendark)\](.*?)\[/color\]`is"'<span class="color_$1">$2</span>'$texto);
    
    
// TAMAÑOS DE TEXTO
    
    // title  [title]texto[/title]
    
$texto preg_replace("`\[title\](.*?)\[/title\]`is"'<span class="FH1">$1</span>'$texto);
    
// subtitle  [subtitle]texto[/subtitle]
    
$texto preg_replace("`\[subtitle\](.*?)\[/subtitle\]`is"'<span class="FSH1">$1</span>'$texto);
    
// H1  [h1]texto[/h1]
    
$texto preg_replace("`\[h1\](.*?)\[/h1\]`is"'<span class="FH1">$1</span>'$texto);
    
// H2  [h2]texto[/h2]
    
$texto preg_replace("`\[h2\](.*?)\[/h2\]`is"'<span class="FH2">$1</span>'$texto); 
    
// H3  [h3]texto[/h3]
    
$texto preg_replace("`\[h3\](.*?)\[/h3\]`is"'<span class="FH3">$1</span>'$texto); 
    
// H4  [h4]texto[/h4]
    
$texto preg_replace("`\[h4\](.*?)\[/h4\]`is"'<span class="FH4">$1</span>'$texto); 
    
    
// URL's INTERNAS
    
$texto preg_replace("`\[web=\s*(.*?)\]\s*(.*?)\s*\[/web\]`is"'<a href="$1" class="home">$2</a>'$texto);

    
// URL's EXTERNAS
    
$texto preg_replace("`\[url\]\s*(.*?)\s*\[/url\]`is"'<a href="$1" onclick="url(\'$1\'); return false;" class="home">$1</a>'$texto);
    
// URL's EXTERNAS
    
$texto preg_replace("`\[url=\s*(.*?)\]\s*(.*?)\s*\[/url\]`is"'<a href="$1" onclick="url(\'$1\'); return false;" class="home">$2</a>'$texto);
    
    
// CITAR MENSAJE
    
$texto preg_replace("`\[citar\]\s*(.+?)\s*\[/citar\]`is"'<span class="bold">Cita:</span><div class="topic_quote">$1</div>'$texto);
    
// CITAR MENSAJE
    
$texto preg_replace("`\[citar=\s*(.+?)\s*\]\s*(.+?)\s*\[/citar\]`is"'<span class="bold">$1</span> escribió:<div class="topic_quote">$2</div>'$texto);
    
    
// MAIL's
    
$texto preg_replace("`\[mail\]\s*(.*?)\s*\[/mail\]`is"'<a href="mailto:$1" class="home">$1</a>'$texto);
    
// MAIL's
    
$texto preg_replace("`\[mail=\s*(.*?)\]\s*(.*?)\s*\[/mail\]`is"'<a href="mailto:$1" class="home">$2</a>'$texto);


    
// IMAGENES
    
$texto preg_replace("`\[img=\"(.*?)\" align=\"(left|right|none|center|galery)\" width=\"(.*?)\" height=\"(.*?)\"\]\s*(.*?)\s*\[/img\]`is"'<div class="img_$2"><img src="$1" alt="$5" title="$5" class="$2" width="$3" height="$4" /><a href="#" onclick="imgzoom(\'$1\'); return false;" class="sec"><br /><img src="img/zoom.gif" alt="" class="middle" /> ver imagen</a></div>'$texto);
    
$texto preg_replace("`\[img=\"(.*?)\" align=\"(left|right|none|center|galery)\" big=\"(.*?)\"\]\s*(.*?)\s*\[/img\]`is"'<div class="img_$2"><img src="$1" alt="$4" title="$4" class="$2" /><a href="#" onclick="imgzoom(\'$3\'); return false;" class="sec"><br /><img src="img/zoom.gif" alt="" class="middle" /> ver imagen</a></div>'$texto);
    
$texto preg_replace("`\[img=\"(.*?)\" align=\"(left|right|none|center|galery)\"\]\s*(.*?)\s*\[/img\]`is"'<div class="img_$2"><img src="$1" alt="$3" title="$3" class="$2" /><a href="#" onclick="imgzoom(\'$1\'); return false;" class="sec"><br /><img src="img/zoom.gif" alt="" class="middle" /> ver imagen</a></div>'$texto);
    
    
// IMAGENES
    
$texto preg_replace("`\[img=\s*(.*?) \s*class=\s*(left|right|none|center|galery)\s*\]\s*(.*?)\s*\[/img\]`is"'<img src="$1" alt="$3" title="$3" class="$2" />'$texto);

    
// IMAGENES
    
$texto preg_replace("`\[img]\s*(.*?)\s*\[/img\]`is"'<img src="$1" alt="" />'$texto);
    
    
// HELP
    
$texto preg_replace("`\[help=\s*(.*?)\s*\]\s*(.*?)\s*\[/help\]`is"'<acronym title="$1">$2</acronym>'$texto);

    
$tips array_keys($_BBcode);
    
$finaltext str_replace($tips,$_BBcode$texto);
    
$finaltext stripslashes($finaltext);
    
$finaltext nl2br($finaltext);
    return 
$finaltext;
  }
?>
Espero puedan ayudarme ya que quiero meterme en este tema...
__________________
I Love Programming...