Problème avec preg_replace_callback
Bonjour tout le monde ! :P
J'ai un petit problème avec la fonction preg_replace_callback : je n'arrive pas à la faire marcher. :mrgreen:
Voiçi une partie de mon script :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <?php
function f($matches)
{
$txt = $matches[1] . $matches[2];
$txt = preg_replace('#<FONT COLOR=\#[0-9a-f]{6}>#', '', $txt);
$txt = str_replace('</FONT>', '', $txt);
return '<FONT COLOR=#0000ff>' . $txt . '</FONT>';
}
$cpp = '// commentaire du fichier "fichier.cpp"';
$htm = $cpp;
$htm = preg_replace('#"(.*)"#iU', '<FONT COLOR=#ff0000>$0</FONT>', $htm);
$htm = preg_replace_callback('#(//)(.+)\n#isU', 'f', $htm);
echo 'Texte en C++ : ' . $cpp . '<br/>';
echo 'Coloré pour HTML : ' . $htm;
?> |
Il donne ceci :
Citation:
Texte en C++ : // commentaire du fichier "fichier.cpp"
Coloré pour HTML : // commentaire du fichier "fichier.cpp"
Alors qu'il devrais donner :
Citation:
Texte en C++ : // commentaire du fichier "fichier.cpp"
Coloré pour HTML : // commentaire du fichier "fichier.cpp"
En fait, c'est la fonction f qui ne s'execute pas ! :(
D'où vient le problème ? 8O
Merci d'avance ! ;)