Gå til innhold

Hvordan får jeg highlight på [code]?


Anbefalte innlegg

Hei

 

Jeg holder på å med min hjemmeside nå, og da lurer jeg på hvordan jeg får til å ha highlight på [ code ]?

 

Coden jeg bruker for å få til [ code ] er:

<?php $input = preg_replace("#\[code](.*?)\[\/code\]#is", "<blockquote><font style='font-family: Courier New;'>$1</font></blockquote>", $input); ?>

 

Jeg har lest litt i php manualen om hvordan jeg får det til, men jeg skjønte det ikke så mye.

http://no.php.net/manual/en/function.highlight-string.php

 

Kan noen hjelpe meg?

 

Edit: 2400 innlegg

Endret av BigJackW
Lenke til kommentar
Videoannonse
Annonse

Fant denne her:

function bb_php($str){
$str = str_replace("]\n", "]", $str);
$match = array('#\[php\](.*?)\[\/php\]#se');
$replace = array("'<div>'.highlight_string(stripslashes('$1'), true).'</div>'");
return preg_replace($match, $replace, $str);
}

Så den klarer du nok overføre til din kode..

Lenke til kommentar

highlight_string(preg_replace("#\

(.*?)\[\/code\]#is", "<blockquote><font style=\'font-family: Courier New;\'>$1</font></blockquote>", $input));

 

Kanskje?

 

Denne siste er riktig. Av en eller annen grunn kom det dobbelpost-

Endret av Zic0
Lenke til kommentar

nå tror jeg at jeg har fått det til (funker i allefall i min bb motor)

function hl_php($a) {
ob_start();
highlight_string(stripslashes($a));
$a	=	ob_get_contents();
ob_end_clean();
return $a;
}


$stuff = <<<PHP
<?php
echo "hello world!";
?>
PHP;

echo preg_replace("#\[php\](.+?)\[/php\]#ie","hl_php(\"\\1\")",$stuff);

Lenke til kommentar

Her er koden for de andre bbkodene:

 

<?php


// Purpose: Activates all BBCode - here we go!

function ChangeFromNewsCodeToHTML($input)
{
   $input = preg_replace("#\\[url=http://([^\"]*?)\\](.*?)\\[/url\\]#si", 
     "<a href=\"http://$1\">$2</a>", $input);

   $input = preg_replace("#\[em](.*?)\[\/em\]#is", "<em>$1</em>", $input);
   $input = preg_replace("#\[b](.*?)\[\/b\]#is", "<strong>$1</strong>", $input);
   $input = preg_replace("#\[i](.*?)\[\/i\]#is", "<em>$1</em>", $input);
   $input = preg_replace("#\[h3](.*?)\[\/h3\]#is", "<h3>$1</h3>", $input);
   $input = preg_replace("#\[u](.*?)\[\/u\]#is", "<u>$1</u>", $input);

   $input = preg_replace("#\[quote](.*?)\[\/quote\]#is", 
     '<div class="quote"><div class="quotetext">' . "$1" . '</div></div>', $input);

 /*#####################
   #####START [ CODE ]####
   #####################*/
  
$input = preg_replace("#\[ code](.*?)\[\/ code\]#is", "<code>$1</code>", $input);

 /*######################
   #####SLUTT  [ CODE ]####
   #####################*/

   // Finds email addresses and makes them clickable ... note that this has to be done before parsing 
   // and making normal links clickable because email addresses will be affected by those regexp's
   $input = preg_replace("#\[url\]([_\.0-9a-zæøå-]+@([0-9a-zæøå]+\.)+[a-z]{2,5})\[\/url\]#is", 
     "<a href=\"mailto:$1\">$1</a>", $input);
   
   $input = preg_replace("#\[url\]((f|ht)tp:\/\/[a-zæøå0-9~\#%@\&:=?\/\.,_-]+[a-z0-9~\#%@\&=?\+\/_-]+)\[\/url\]#is", 
     "<a href=\"$1\">$1</a>", $input); // http

   $input = preg_replace("#\[url\]((www.)?[a-zæøå0-9~\#%@\&:=?\/\.,_-]+[a-z0-9~\#%@\&=?\+\/_-]+)\[\/url\]#is", 
     "<a href=\"http://$1\">$1</a>", $input); // www

   $input = preg_replace("#\[quote=(.*?)\](.*?)\[\/quote\]#is", '<div class="quote"><div class="quotename">' . "$1" . '</div><div class="quotetext">' . "$2" . '</div></div>', $input);
/*
   $input = preg_replace("/((f|ht)tp:\/\/[a-z0-9~#%@\&:=?\/\.,_-]+[a-z0-9~#%@\&=?\+\/_-]+)/i", "<a href=\"\\1\">\\1</a>", $input); //http
   $input = preg_replace("/([[:space:]a-z0-9{()\"'\[~#%@\&:=?\._-])(www.[a-z0-9~#%@\&:=?\/\.,_-]+[a-z0-9~#%@\&=?\+\/_-]+)/i", "\\1<a href=\"http://\\2\">\\2</a>", $input); // www.
   $input = preg_replace("/([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})/i", "<a href=\"mailto:\\1\">\\1</a>", $input); // mail
*/

   return $input;
} // end function
 
 
 ?>

 

Hvordan kan jeg få highlight på [ code ] taggen da?

Endret av BigJackW
Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...