Ver Mensaje Individual
  #7 (permalink)  
Antiguo 15/04/2010, 15:09
Avatar de GatorV
GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Respuesta: preg_replace con Patron de Expresiones Regulares

Lee en el manual como funciona el tipo callback, puedes hacerlo de dos formas, via instancia:
Código PHP:
Ver original
  1. class foo {
  2.         public function doSomething($val) {
  3.                  return ucfirst($val[0]);
  4.        }
  5. }
  6.  
  7. $foo = new foo();
  8. $text = preg_replace_callback($pattern, array($foo, 'doSomething'), $text);

o via estatica:
Código PHP:
Ver original
  1. class foo {
  2.         public static function doSomething($val)
  3.         {
  4.                  retun strtolower($val[0]);
  5.         }
  6. }
  7.  
  8. $text = preg_replace_callback($pattern, array('foo', 'doSomething'), $text);

Saludos.