Anidar funciones dentro de funciones, que aunque posible, no es correcto.
Para dicho caso conviene mejor usar objetos.
Código PHP:
class BBCodeExpand {
private $idn;
private $string;
public function __construct($string, $idn)
{
$this->idn = $idn;
$this->string = $string;
$this->string = preg_replace_callback('/#(\d+)\b/', array($this, 'mi_callback'), $this->string);
}
public function salida()
{
return $this->string;
}
public function mi_callback($match){
return $this->ProcessQuote($match[1], $this->idn); // el número
}
public function ProcessQuote($match, $idn){
# Buscamos el post del quote
ConexionDB();
# Get Relacionadas
$query = mysql_query('SELECT mensaje FROM noticias_comentarios WHERE idn = "'.$idn.'" AND idp = "'.$match.'"');
$check = mysql_num_rows($query);
if($check == 0) {
return '<a class="tooltip" href="#'.$match.'" ref="El mensaje #'.$match.' no existe"><strong>#'.$match.'</strong></a>';
}else{
$fetch = mysql_fetch_array($query);
return '<a class="tooltip" href="#'.$match.'" ref="'.$fetch['mensaje'].'"><strong>#'.$match.'</strong></a>';
}
}
}
$obj = new BBCodeExpand($string, $idn);
echo $obj->salida();