geshi et quotes

Eléphant du PHP | 451 Messages

28 déc. 2009, 00:54

C'est bon j'ai trouver grasse a ton lien

Voici la fonction exact:
<?php

function getGeshi($match) {
        include_once('geshi/geshi.php'); // Inclure la librairie GeSHi

        $geshi = new GeSHi($match[2], $match[1]); // Créer un objet "GeSHi"
       
        $code = '<table width="1000" border="0" cellspacing="0" cellpadding="0"><tr><td height="20" background="images/quoteh.gif">&nbsp;</td></tr><tr><td background="images/quotem.gif"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>'.$geshi->parse_code().'</td></tr></table></td></tr><tr><td height="20" background="images/quoteb.gif"></td></tr></table>';

        return $code; // Retourne le résultat
}

function ChangeBR($retour) {
        $retour[1] = preg_replace("`\<br((\s*)\/?)\>`ims", '[[br]]', $retour[1]);
       
        return $retour[1];
}

function nl2brCallback($retour) {
        $retour[1] = preg_replace("`\<br((\s*)\/?)\>`ims", '', $retour[1]);
        $retour[1] = preg_replace("`\[\[br\]\]+`ims", "\r", $retour[1]);
       
        return $retour[1];
}

$text = code(nl2br($tuto['tuto_tuto']));

$text = preg_replace_callback("`(\[quote=(as|php|css)\]+(.*?)\[\/quote\])`isSm", 'ChangeBR', $text);
$text = preg_replace_callback("`(\[quote=(as|php|css)\]+(.*?)\[\/quote\])`isSm", 'nl2brCallback', $text);
$text = preg_replace_callback('/\[quote=(.*?)\](.*?)\[\/quote\]/is', 'getGeshi', $text);

echo $text;

?>
Dans le masque (as|php|css) de la regex il faudra que tu mette tout les language autorisé comme ceci:

(as|php|css|js|html|sharp|java|sql|etc)

Eléphant du PHP | 299 Messages

28 déc. 2009, 01:12

Alors milles mercis a DJTEC qui a pris de son temps pour m' aider, et avoir trouver aussi vite la reponse.

Pour ceux donc qui utilisent geshi avec ce probleme de nl2br ou de <br /> pour les debutants, adaptez ce morceaux a votre code.

					                                                    <?php


 $tuto_tuto = nl2br(htmlentities(stripslashes($tuto['tuto_tuto'])));


function getGeshi($match) {
        include_once('geshi/geshi.php'); // Inclure la librairie GeSHi

        $geshi = new GeSHi($match[2], $match[1]); // Créer un objet "GeSHi"
       
        $code_geshi = $geshi->parse_code();
       
        $code = '<table width="1000" border="0" cellspacing="0" cellpadding="0"><tr><td height="20" background="images/quoteh.gif">&nbsp;</td></tr><tr><td background="images/quotem.gif"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>'.$code_geshi.'</td></tr></table></td></tr><tr><td height="20" background="images/quoteb.gif"></td></tr></table>';

        return $code; // Retourne le résultat
}

$text = code(nl2br(stripslashes($tuto['tuto_tuto'])));

function ChangeBR($retour) {
        $retour[1] = preg_replace("`\<br((\s*)\/?)\>`ims", '[[br]]', $retour[1]);
       
        return $retour[1];
}

function nl2brCallback($retour) {
        $retour[1] = preg_replace("`\<br((\s*)\/?)\>`ims", '', $retour[1]);
        $retour[1] = preg_replace("`\[\[br\]\]+`ims", "\r", $retour[1]);
       
        return $retour[1];
}

$text = preg_replace_callback("`(\[quote=(as|php|css|sql|javascript|html4strict)\]+(.*?)\[\/quote\])`isSm", 'ChangeBR', $text);
$text = preg_replace_callback("`(\[quote=(as|php|css|sql|javascript|html4strict)\]+(.*?)\[\/quote\])`isSm", 'nl2brCallback', $text);
$text = preg_replace_callback('/\[quote=(.*?)\](.*?)\[\/quote\]/is', 'getGeshi', $text);

echo $text;

?>

Eléphant du PHP | 451 Messages

28 déc. 2009, 01:15

De rien graffx PhpFrance à été conçu pour l'entraide.

Ravie de t'avoir aidé et bonne continuation pour ton site.

++

Eléphant du PHP | 299 Messages

28 déc. 2009, 01:17

Merci mon ami, c' est sur que ce forum est fait pour l' entraide, mais c' est le seul qui a pas attrappé la grosse tête :mrgreen:

A charge de revanche comme promis =D>