Jump to content


code box


3 replies to this topic

#1 Bl4ck-Vip3r

    Young Padawan

  • Members
  • Pip
  • 41 posts

Posted 24 March 2007 - 06:10 PM

I have got my tms up and running and it allows me to add edit del tuts etc .... but i was wondering since i am going to be making php and html tuts i will need to intergrate a codebox into it and i have seen most codeboxes shop the php code the same as in say dreamwaver (the correct colours and indents etc) i was wondering if this is manual coding or if i is like a build in php function? if not any help on how i would make one? thanks

#2 Braunson

    Young Padawan

  • Members
  • Pip
  • 237 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 24 March 2007 - 11:20 PM

highlight_string and some style and your ready to goo ;)

#3 Bl4ck-Vip3r

    Young Padawan

  • Members
  • Pip
  • 41 posts

Posted 25 March 2007 - 05:08 AM

here are two functions i found which use like bbcode and i was wondering, do i need to like call the functions or what because i made an example with one and the code just gets parsed. here they are, the example is at the bottom.
<?php
 function bb_url($str){
 return preg_replace('#[URL=([^\']*)]([^\']*)[/URL]#', '<a href="\\1" target=_blank>\\2</a>', $str);
 }
 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);
 }
 function bb_img($str){
 return preg_replace('#[IMG]([^\']*)[/IMG]#', '<img src="\\1" />', $str);
 }
 function bb_b{$str){
 return preg_replace('#[B]([^\']*)[/B]', '<strong>\\1</strong>', $str);
 }
 function bb_i{$str){
 return preg_replace('#[I]([^\']*)[/I]', '<em>\\1</em>', $str);
 }
 function bb_parse{$str){
 $str = bb_url($str);
 $str = bb_php($str);
 $str = bb_img($str);
 $str = bb_b($str);
 $str = bb_i($str);
 return $str
 }
 ?>




Example one.


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



echo '
This is the php code i want highlighting,: <br /> [php]<php include "Connect.php"; // this is the connect file ?>[/php]';
?>


#4 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 25 March 2007 - 11:35 AM

Here's a topic that should give you a wealth of information for using code tags.
http://www.pixel2life.com/forums/index.php...0&hl=bbcode

Also, if you want to get fancy with code parsing and highlighting, you could use the GeSHi Library. It works quite well, and is simple to implement into your own BBCode class if you were to create one.

Edited by Demonslay, 25 March 2007 - 11:36 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users