+1 ! LES CONS ENFORCE !Dobro a écrit :si tu pense a l'eradication des cons , ça va etre durIl y a d'autres choses qui pourraient rendre le forum plus vivable,![]()
......... je resiste !!

Le pire, c que ce n'est pas si faux...

Code : Tout sélectionner
/**
Converti un texte sans tenir compte du texte, des constantes, etc...
Il faut donc juste passer une partie correcte
*/
function convSyntaxePB($text)
{
if (strlen($text) < 2)
return $text;
if (ereg("^[+-]", $text))
$text = " " . $text;
else
$text = " " . $text;
// Enjoliver le texte en rajoutant des espaces
$text = ereg_replace("(:)([a-zA-Z0-9\"$])", "\\1 \\2", $text);
$text = ereg_replace("([+])([a-zA-Z0-9\"$])", "\\1 \\2", $text);
$text = ereg_replace("([a-zA-Z0-9\"$])([+])", "\\1 \\2", $text);
$text = ereg_replace("([-])([a-zA-Z0-9\"$])", "\\1 \\2", $text);
$text = ereg_replace("([a-zA-Z0-9\"$])([-])", "\\1 \\2", $text);
$text = ereg_replace("([=])([a-zA-Z0-9\"$])", "\\1 \\2", $text);
$text = ereg_replace("([a-zA-Z0-9\"$])([=])", "\\1 \\2", $text);
// Coloration pour les fonctions
while (substr_count($text, " ("))
$text = str_replace(" (", "(", $text);
$lastFound = -1;
while( ($lastFound+1)<strlen($text) && ($lastFound = strpos($text, "(", $lastFound+1)) )
{
$offset = 0;
$i = $lastFound - 1;
$car = $text{$i};
while ( $i >= 0 && isFctLetter($text{$i}) )
$i--;
if ($text{$i}=='.')
{
$offset = $lastFound - $i;
$i--;
while ( $i >= 0 && isFctLetter($text{$i}) )
$i--;
}
if (($lastFound - $i)>1 && $i>=0)
{
$i++;
$text = substr($text, 0, $i) . "<font class=\"fct\">"
. substr($text, $i, $lastFound-($i+$offset)) . "</font>"
. substr($text, $lastFound-$offset, strlen($text)+$offset+1-$lastFound);
$lastFound = $lastFound + strlen("<font class=\"fct\"></font>")+1;
}
}
// Coloration des mots clés
$keyWord = Array("ElseIf", "EndIf", "Else", "For", "To", "Next", "Repeat", "If", "Goto",
"Until", "While", "Wend", "ProcedureReturn", "Procedure", "EndProcedure",
"Enumeration", "EndEnumeration", "Global", "And", "Or", "Select", "Case",
"Default", "EndSelect", "Structure", "EndStructure", "End", "Shared", "Dim",
"Debug", "Protected", "NewList", "Restore", "Break", "Continue", "ForEach",
"ForEver", "Gosub", "FakeReturn", "Return", "Interface", "EndInterface",
"Declare", "IncludeFile", "XIncludeFile");
$KeyWithPoint = Array("Procedure", "Declare");
foreach($keyWord as $key)
$text = str_replace(" $key ", " <font class=\"bloc\">$key</font> ", $text);
foreach($KeyWithPoint as $key)
$text = str_replace(" $key.", " <font class=\"bloc\">$key</font>.", $text);
$text = substr($text, 1, strlen($text)-1);
return $text;
}
function isFctLetter($car)
{
return (eregi("[a-z0-9_]", $car));
}
function lineToPbFont($line)
{
$out = "";
$nbSpace = strlen($line) - strlen(ltrim($line));
$line = " " . trim($line). " ";
$pbText = "";
$line = ereg_replace("([a-zA-Z0-9\"$])(=)([a-zA-Z0-9\"])", "\\1 = \\3", $line);
$line = ereg_replace("([a-zA-Z0-9\"$ ])(=)([a-zA-Z0-9\"])", "\\1= \\3", $line);
$line = ereg_replace("([a-zA-Z0-9\"$])(=)([a-zA-Z0-9\" ])", "\\1 =\\3", $line);
for($i=0; $i<strlen($line); $i++)
{
switch($line{$i})
{
case '"':
$out = $out . convSyntaxePB($pbText);
$pbText = "";
$pos = strpos($line, '"', $i+1);
if($pos)
{
$out = $out."<font class=\"mot\">".substr($line, $i, $pos+1-$i)."</font>";
$i = $pos;
}
break;
case "'":
$out = $out . convSyntaxePB($pbText);
$pbText = "";
$pos = strpos($line, "'", $i+1);
if($pos)
{
$out = $out."<font class=\"mot\">".substr($line, $i, $pos+1-$i)."</font>";
$i = $pos;
}
break;
case "!":
$out = $out . convSyntaxePB($pbText);
$pbText = "";
$pos = strpos($line, " ", $i+1);
if($pos)
{
$out = $out."<font class=\"diese\">".substr($line, $i, $pos-$i)."</font> ";
$i = $pos;
}
break;
case "#":
$out = $out . convSyntaxePB($pbText);
$pbText = "";
$j = $i+1;
$car = strtolower($line{$j});
while ( ($car == '_' || ($car >= 'a' && $car <= 'z')) && ($j < strlen($line)) ) {
$j++; $car = strtolower($line{$j}); }
if ($j < strlen($line))
{
$j--;
$out = $out."<font class=\"diese\">".substr($line, $i, $j+1-$i)."</font>";
$i = $j;
}
break;
case ";":
$out = $out . convSyntaxePB($pbText);
if ($i>0 && $line{$i-1} != ' ')
$out = $out . " ";
$pbText = "";
$out = $out . "<font class=\"comment\">".ereg_replace("^([;])([a-zA-Z0-9\"_$])", "\\1 \\2", substr($line, $i, strlen($line)-($i+1)))."</font>";
$i = strlen($line);
break;
default:
$pbText = $pbText . $line{$i};
if ( ($line{$i} == ',') && ($line{$i+1} != ' ') )
$pbText = $pbText . " ";
}
}
$out = trim($out . convSyntaxePB($pbText));
for($i=0; $i<$nbSpace; $i++)
$out = " " . $out;
return $out;
}
function texteToPbFont($texte)
{
$newLine = chr(13).chr(10);
$arr = explode($newLine, $texte);
$texte = "";
foreach($arr as $key)
$texte = $texte . lineToPbFont($key) . $newLine;
return $texte;
}
Code : Tout sélectionner
.texte {
text-decoration:none;
font-size: 13px;
font-weight : normal;
font-family : Courrier;
color: #000000 ;
}
.fct {
text-decoration:none;
font-size: 14px;
font-weight : normal;
font-family : Courrier;
color: #006666 ;
}
.bloc {
text-decoration:none;
font-size: 14px;
font-weight : bold;
font-family : Courrier;
color: #006666 ;
}
.comment {
text-decoration:none;
font-size: 14px;
font-weight : normal;
font-family : Courrier;
color: #00AAAA ;
}
.mot {
text-decoration:none;
font-size: 14px;
font-weight : normal;
font-family : Courrier;
color: #808080 ;
}
.diese {
text-decoration:none;
font-size: 14px;
font-weight : normal;
font-family : Courrier;
color: #924B72 ;
}
Code : Tout sélectionner
<pre>
<?php
echo texteToPbFont($myPBSource);
?>
</pre>