problem mit BBcode highlight_string

kcyberbob

Erfahrenes Mitglied
Hallo ich habe ein Problem mit folgendem Script:

PHP:
<?
$text = trim(stripslashes($text)); 
function hstring($s) 
{ 
    ob_start(); 
    highlight_string("<? ".$s."?>"); 
    $c = ob_get_contents(); 
    ob_end_clean(); 
    return $c; 
} 

function bbcode($s)
{
while(preg_match("=\[code\](.*)\[/code\]=Uis",$s)!=FALSE) 
{ 
 $res=preg_match("=\[code\](.*)\[/code\]=Uis",$s,$matches); 
 if($res) 
 { 

  $block=hstring($matches[1]); 
  $block=preg_replace("=<\?=Uis","",$block); 
  $block=preg_replace("=\?>;=Uis","",$block); 
  $block=preg_replace("=&amp;lt;=Uis","<",$block); 
  $block=preg_replace("=&amp;gt;=Uis",">;;",$block); 
  $s=preg_replace("=\[code\](.*)\[/code\]=Uis",$block,$s,1); 
 } 
} 

return($s);  
}
if ($action == "see") {
$ausgabe = bbcode($text); 
   echo "$ausgabe"; 
   echo "<br>";
      }
  
if ($action == "send") {
?>
<form name="form1" method="post" action="test.php?action=see">
  <textarea name="text" cols="80" rows="20"></textarea>
  <input type="submit" name="Submit" value="Abschicken">
</form>
<?
}
?>

So aber jetzt zu meinem Problem.
Also wenn ich jetzt einen Code eingebe dann functioniert alles aber bei der ausgabe habe ich immer alles in foglenden klammern stehen <? ?>
wie bekomme ich die weg so das der code genau so in farbe dargestellt wird.
Im Prinzip wie in diesem Forum hier.

Gruß kcyberbob

PS: Würde mich freuen wenn ihr mir weiterhelfen könntet.
 
Devil Noxx: :rolleyes:

Vielleicht suchst du ja das hier:
Code:
function highlight_php( $a_sString )
{
    $bTags = true;
    if (   ( strpos( $a_sString, "<?" ) === false )
        && ( strpos( $a_sString, "?>" ) === false ) ) {
        $a_sString = "<?php".$a_sString."?>";
        $bTags = false;
    }
    ob_start();
    highlight_string( $a_sString );
    $sRetVal = ob_get_contents();
    ob_end_clean();

    if ( $bTags == false ) {
        $sRetVal = str_replace( "&lt;?php", "", $sRetVal );
        $sRetVal = str_replace( "?&gt;", "", $sRetVal );
    }

    $sRetVal = str_replace( "\n", "", $sRetVal );
    $sRetVal = str_replace( "<br />", "", $sRetVal );

    return $sRetVal;
}

$sData = preg_replace( "/\[code\](.*?)\[\/code\]/ise",
                       "highlight_php('$1');",
                       $sData );
 
Zurück