Jump to content

Help with a new bbs code function...


Code Warrior

Recommended Posts

Hello, first time poster. I'm an old time programmer deciding to get back into the swing of things by writting my own bbs in php backended with mysql on apache. I'm not entirely pleased with the way standard BB codes work and was working out my own technique for doing this on my board. It looks good sofar on the browsers I have here but maybe I could get some bashing around by you all to optimize / clean it up a bit.

 

<?php

function str_textcodes($strin)
{
   // dos colors to html colors
   $d2h_colors = array(
      '#000','#a00','#0a0','#a50','#00a','#a0a','#0aa','#aaa',
      '#555','#f55','#5f5','#ff5','#55f','#f5f','#5ff','#fff'
   );

   // font sizes 0-6
   $fontsizes = array(
      'xx-small','x-small','small','medium','large','x-large','xx-large'
   );
   
   // attribute flags...
   $at_italics    = FALSE; // italics
   $at_bold       = FALSE; // bold
   $at_underline  = FALSE; // underline
   $at_through    = FALSE; // strike through
   $at_overline   = FALSE; // over line
   $at_blink      = FALSE; // blink
   $at_supers     = FALSE; // superscript
   $at_subs       = FALSE; // subscript

   $at_font       = 0;
   $at_fontchange = FALSE;
   $at_fcolor     = "black";
   $at_bcolor     = "white";
   $at_fcolorchange = FALSE;
   $at_bcolorchange = FALSE;
   $at_fontsize   = 3;  // default size
   $at_fontsizechange = FALSE;

   $at_paragraph  = FALSE;

   $at_change     = FALSE;
   $at_changecnt  = 0;
   $out = "";
   for ($i = 0; $i < strlen($strin); $i++)
   {
      if ($strin[$i] == '^')
      {
         // gather up codes until non-code encountered.
         $i++;
         switch ($strin[$i])
         {
            case '0':
               $at_italics =  $at_bold = $at_underline = $at_through = 
               $at_overline = $at_blink = $at_propfont = $at_monofont = 
               $at_supers = $at_subs = FALSE;
               $at_fcolor = "black";
               $at_bcolor = "white";
               $at_fontsize = 3;
               $at_fontchange = FALSE;
               $at_fcolorchange = FALSE;
               $at_bcolorchange = FALSE;
               $at_change = FALSE;
               for (; $at_changecnt > 0; $at_changecnt--)
                  $out .= "</span>";
               break;

            case 'i':
               $at_italics = TRUE;
               $at_change = TRUE;
               break;

            case 'e':
               $at_bold = TRUE;
               $at_change = TRUE;
               break;

            case 'u':
               $at_underline = TRUE;
               $at_change = TRUE;
               break;

            case 't':   
               $at_through = TRUE;
               $at_change = TRUE;
               break;

            case 'o':
               $at_overline = TRUE;
               $at_change = TRUE;
               break;

            case 'x':
               $at_blink = TRUE;
               $at_change = TRUE;
               break;

            case 'f':
               $at_fontchange = TRUE;
               $at_change = TRUE;
               $i++;
               switch ($strin[$i])
               {
                  case 'p':
                     $at_font = 1;
                     break;

                  case 'm':
                     $at_font = 2;
                     break;

                  case 'c':
                     $at_font = 3;
                     break;

                  case 'f':
                     $at_font = 4;
                     break;

                  case 's':
                     $at_font = 5;
                     break;

                  default:
                     break;
               }
               break;

            case '~':
               $at_supers = TRUE;
               $at_change = TRUE;
               break;

            case '_':
               $at_subs = TRUE;
               $at_change = TRUE;
               break;

            case 'r':
               $x = $at_fcolor;
               $at_fcolor = $at_bcolor;
               $at_bcolor = $x;
               $at_change = TRUE;
               $at_fcolorchange = TRUE;
               $at_bcolorchange = TRUE;
               break;

            case 'c':
               $i++;
               $at_fcolor = $d2h_colors[hexdec($strin[$i])];
               $at_fcolorchange = TRUE;
               $at_change = TRUE;
               break;

            case 'b':
               $i++;
               $at_bcolor = $d2h_colors[hexdec($strin[$i])];
               $at_bcolorchange = TRUE;
               $at_change = TRUE;
               break;

            case 'C':
               $i++;
               $at_fcolor = '#'.strtoupper(substr($strin, $i, 6));
               $i += 5;
               $at_fcolorchange = TRUE;
               $at_change = TRUE;
               break;

            case 'B':
               $i++;
               $at_bcolor = '#'.strtoupper(substr($strin, $i, 6));
               $i += 5;
               $at_bcolorchange = TRUE;
               $at_change = TRUE;
               break;

            case 's':
               $i++;
               $s = $strin[$i];
               if (($s >= '0') && ($s <= '6'))
                  $at_fontsize = intval($s);
               else
                  $at_fontsize = 3;
               $at_fontsizechange = TRUE;
               $at_change = TRUE;
               break;

            case 'p':
               if ($at_paragraph)
                  $out .= '</P>';
               $at_paragraph  = TRUE;
               $out .= '<P>';
               break;

            case 'P':
               if ($at_paragraph)
                  $out .= '</P>';
               $at_paragraph  = TRUE;
               $i++;
               switch ($strin[$i])
               {
                  case 'l':
                     $out .= "<P style='text-align: left;'>";
                     break;

                  case 'r':
                     $out .= "<P style='text-align: right;'>";
                     break;

                  case 'j':
                     $out .= "<P style='text-align: justify;'>";
                     break;

                  case 'c':
                     $out .= "<P style='text-align: center;'>";
                     break;

                  case 'L':
                     $out .= "<P style='text-align: left; text-indent: 32px;'>";
                     break;

                  case 'R':
                     $out .= "<P style='text-align: right; text-indent: 32px;'>";
                     break;

                  case 'J':
                     $out .= "<P style='text-align: justify; text-indent: 32px;'>";
                     break;

                  case 'C':
                     $out .= "<P style='text-align: center; text-indent: 32px;'>";
                     break;

                  case 'i':
                     $out .= "<P style='text-align: left; padding-left: 32px;'>";
                     break;

                  default:
                     $out .= "<P>";
                     $i--;
                     break;
               }
               break;

            case 'n':         $out .= "<br>";      break;

            case 'g':

         if ($at_change)
         {
            $r = "<span style='";
            if ($at_italics)
               $r .= "font-style: italic; ";
            if ($at_bold)
               $r .= "font-weight: bold; ";

            if ($at_supers || $at_subs)
            {
               if ($at_supers)
                  $r .= "vertical-align: top; font-size: 50%; ";
               else
                  $r .= "vertical-align: bottom; font-size: 50%; ";
            }

            if ($at_underline || $at_through || $at_overline || $at_blink)
            {
               $r .= "text-decoration: ";
               if ($at_underline)
                  $r .= "underline ";
               if ($at_through)
                  $r .= "line-through ";
               if ($at_overline)
                  $r .= "overline ";
               if ($at_blink)
                  $r .= "blink ";
               $r .= "; ";
            }
            if ($at_fontchange)
            {
               switch ($at_font)
               {
                  case 1:
                     $r .= "font-family: serif; white-space: normal; ";
                     break;

                  case 2:
                     $r .= "font-family: monospace; white-space: normal; ";
                     break;

                  case 3:
                     $r .= "font-family: monospace; white-space: pre; ";
                     break;

                  case 4:
                     $r .= "font-family: fantasy; white-space: normal; ";
                     break;

                  case 5:
                     $r .= "font-family: cursive; white-space: normal; ";
                     break;

                  default:
                     break;
               }
            }
            if ($at_fontsizechange)
               $r .= "font-size: ".$fontsizes[$at_fontsize]."; ";

            if ($at_fcolorchange && ($at_fcolor !== ""))
               $r .= "color: ".$at_fcolor."; ";

            if ($at_bcolorchange && ($at_bcolor !== ""))
               $r .= "background-color: ".$at_bcolor."; ";

            $r .= "'>";
            $out .= $r;          
            $at_change = FALSE;
            $at_fcolorchange = FALSE;
            $at_bcolorchange = FALSE;
            $at_fontsizechange = FALSE;
            $at_fontchange = FALSE;
            $at_changecnt++;
         }

               $i++;
               switch ($strin[$i])
               {
                  case '0':   $out .= '&#x2591;';  break;
                  case '1':   $out .= '&#x2592;';  break;
                  case '2':   $out .= '&#x2593;';  break;
                  case '3':   $out .= '&#x2588;';  break;
                  case 't':   $out .= '&#x2580;';  break;
                  case 'b':   $out .= '&#x2584;';  break;
                  case 'l':   $out .= '&#x258c;';  break;
                  case 'r':   $out .= '&#x2590;';  break;
                  case 'q':   $out .= '&#x250c;';  break;
                  case 'w':   $out .= '&#x252c;';  break;
                  case 'e':   $out .= '&#x2510;';  break;
                  case 'a':   $out .= '&#x251c;';  break;
                  case 's':   $out .= '&#x253c;';  break;
                  case 'd':   $out .= '&#x2524;';  break;
                  case 'z':   $out .= '&#x2514;';  break;
                  case 'x':   $out .= '&#x2534;';  break;
                  case 'c':   $out .= '&#x2518;';  break;
                  case 'v':   $out .= '&#x2502;';  break;
                  case 'h':   $out .= '&#x2500;';  break;

                  default:    $out .= ' ';    $i--; break;
               }
               break;

            case '^':         $out .= '^';         break;

            default:
               break;
         }
      }
      else
      {
         if ($at_change)
         {
            $r = "<span style='";
            if ($at_italics)
               $r .= "font-style: italic; ";
            if ($at_bold)
               $r .= "font-weight: bold; ";

            if ($at_supers || $at_subs)
            {
               if ($at_supers)
                  $r .= "vertical-align: top; font-size: 50%; ";
               else
                  $r .= "vertical-align: bottom; font-size: 50%; ";
            }

            if ($at_underline || $at_through || $at_overline || $at_blink)
            {
               $r .= "text-decoration: ";
               if ($at_underline)
                  $r .= "underline ";
               if ($at_through)
                  $r .= "line-through ";
               if ($at_overline)
                  $r .= "overline ";
               if ($at_blink)
                  $r .= "blink ";
               $r .= "; ";
            }
            if ($at_fontchange)
            {
               switch ($at_font)
               {
                  case 1:
                     $r .= "font-family: serif; white-space: normal; ";
                     break;

                  case 2:
                     $r .= "font-family: monospace; white-space: normal; ";
                     break;

                  case 3:
                     $r .= "font-family: monospace; white-space: pre; ";
                     break;

                  case 4:
                     $r .= "font-family: fantasy; white-space: normal; ";
                     break;

                  case 5:
                     $r .= "font-family: cursive; white-space: normal; ";
                     break;

                  default:
                     break;
               }
            }
            if ($at_fontsizechange)
               $r .= "font-size: ".$fontsizes[$at_fontsize]."; ";

            if ($at_fcolorchange && ($at_fcolor !== ""))
               $r .= "color: ".$at_fcolor."; ";

            if ($at_bcolorchange && ($at_bcolor !== ""))
               $r .= "background-color: ".$at_bcolor."; ";

            $r .= "'>";
            $out .= $r;          
            $at_change = FALSE;
            $at_fcolorchange = FALSE;
            $at_bcolorchange = FALSE;
            $at_fontsizechange = FALSE;
            $at_fontchange = FALSE;
            $at_changecnt++;
         }
         /* output it. */
         $out .= $strin[$i];
      }
   }
   for (; $at_changecnt > 0; $at_changecnt--)
      $out .= "</span>";
   if ($at_paragraph)
      $out .= '</P>';
   return $out;
}

$str = <<<EOS
^e^c1^s5TEXT CODES:^0 can be used in text messages, articles, and bulletins posted by users on the BBS.
^p^i^uRESET^0^n
^fm^^0^0 = Reset all attribute changes; clean slate; everything reset to defaults...
^p^i^uATTRIBUTES^0^n
^fm^^e^0 = ^eBold^0^n
^fm^^i^0 = ^iItalics^0^n
^fm^^u^0 = ^uUnderline^0^n
^fm^^t^0 = ^tStrike through^0^n
^fm^^o^0 = ^oOver-line^0^n
^fm^^x^0 = ^xBlink^0 (not supported on all browsers)
^p^i^uSCIENTIFIC^0^n
^fm^^~^0 = ^~Superscript^0 (These two are mutually exclusive)^n 
^fm^^_^0 = ^_Subscript^0
^p^i^uTYPE-FACES^0^n
^fm^^f^in^0 = Type-face font (dependent on browser) where ^i^fmn^0 = ^n
^Pi^fmp^0 ^fpproportional^0^n
^fmm^0 ^fmmonospaced^0^n
^fcc^0 ^fccode^0^n
^fcf^0 ^fffantasy^0^n
^fcs^0 ^fsscript^0^n
^p^i^uTYPE-FACE SIZING^0^n
^fm^^s#^0 = Change font size. (0=^s0smallest^0, 3=^s3normal^0 6=^s6largest^0)
^p^i^uCOLORING^0^n
^fm^^r^0 = ^rreverse^0. (swap foreground and background colors)^n
^fm^^C^i######^0 = change foreground color with hex (rrggbb) color.^n
^fm^^B^i######^0 = change background color with hex (rrggbb) color.^n
^fm^^c#^0 = change foreground color with quick color. (below)^n
^fm^^b^i#^0 = change background color with quick color. (below)^n
^Pi^fm0^0 ^c0Black^0^n
^fm1^0 ^c1Red^0^n
^fm2^0 ^c2Green^0^n
^fm3^0 ^c3Brown^0^n
^fm4^0 ^c4Blue^0^n
^fm5^0 ^c5Magenta^0^n
^fm6^0 ^c6Cyan^0^n
^fm7^0 ^b0^c7Light Gray^0^n
^fm8^0 ^c8Dark Gray^0^n
^fm9^0 ^b0^c9Bright Red^0^n
^fmA^0 ^b0^caBright Green^0^n
^fmB^0 ^b0^cbYellow^0^n
^fmC^0 ^b0^ccBright Blue^0^n
^fmD^0 ^b0^cdBright Magenta^0^n
^fmE^0 ^b0^ceBright Cyan^0^n
^fmF^0 ^b0^cfWhite^0
^p^i^uFORMATTING^0^n
^fm^^n^0 = new line^n
^fm^^p^0 = new paragraph^n
^fm^^P^ix^0 = new paragraph with justification/indentation.
^Pi^fml^0 left^n
^fmr^0 right^n
^fmc^0 center^n
^fmj^0 justify^n
^fmL^0 left w/indent^n
^fmR^0 right w/indent^n
^fmC^0 center w/indent^n
^fmJ^0 justify w/indent^n
^fmi^0 indent entire paragraph
^p^i^uSPECIAL CHARACTERS^0^n
^fm^^^^^0 = ^^^n
^fm^^g^in^0 = graphic character.  (not supported on all browsers) Where ^fm^in^0 =^n
^Pi^fm0^0 ^g0^n
^fm1^0 ^g1^n
^fm2^0 ^g2^n
^fm3^0 ^g3^n
^fmt^0 ^gt^n
^fmb^0 ^gb^n
^fml^0 ^gl^n
^fmr^0 ^gr^n
^fmq^0 ^gq^n
^fmw^0 ^gw^n
^fme^0 ^ge^n
^fma^0 ^ga^n
^fms^0 ^gs^n
^fmd^0 ^gd^n
^fmz^0 ^gz^n
^fmx^0 ^gx^n
^fmc^0 ^gc^n
^fmv^0 ^gv^n
^fmh^0 ^gh^n
^p
^fp^i^eThe above was generated with...^0^n
EOS;

   echo str_textcodes($str).'<br><br>';
   echo '<pre><code>'.$str.'</code></pre>';

?>

 

CW

Link to comment
Share on other sites

Holy Cow, that looks like similar code to the old modem BBS codes.

 

ya can do lots of optimizing, lots of switches.

 

A lot of the switch statements can be replaced with preg_replace statements, regex may be difficult to get started with, but once ya get started, it makes things like search/replace and pattern searching a whole lot easier.

 

Link to comment
Share on other sites

Holy Cow, that looks like similar code to the old modem BBS codes.

 

ya can do lots of optimizing, lots of switches.

 

A lot of the switch statements can be replaced with preg_replace statements, regex may be difficult to get started with, but once ya get started, it makes things like search/replace and pattern searching a whole lot easier.

 

 

Exactly. I used to run a 4 node BBS back in the early 90's and wrote alot of door programs and utilities. I'll try to get this mess tweaked using regex as much as possible but parsing with it can be tricky as what is being interpreted depends greatly upon what appeared before it. I also have a working ANSI screen to HTML function that needs the same treatment so I have my work cut out for me. ;) I wish I had the luxury of writting the whole thing in C but alot of hosts frown upon rogue binaries.

 

Cheerio,

CW

Link to comment
Share on other sites

One thing that I liked about php, moving from C to php was that much easier because the similarities.

I used to work on several BBS's in the early 90's as well, I was doing a lot of mods for 4 different sites (WWIV).

the code does look interersting, i'll take a look later on today.

 

 

 

Link to comment
Share on other sites

When I went over the code, I do get a lot of what's going on.

and preg_match, may just overcomplicate the code u have already.

 

but we can still change some things around :)

<?php

  // attribute flags...
   define('AT_ITALICS',1);
   define('AT_BOLD',2);
   define('AT_UNDERLINE',4);
   define('AT_THROUGH',;
   define('AT_OVERLINE',16);
   define('AT_BLINK',32);
   define('AT_SUPERS',64);
   define('AT_SUBS',128);
   define('AT_FONTCHANGE',256);
   define('AT_FCOLORCHANGE',512);
   define('AT_BCOLORCHANGE',1024);
   define('AT_FONTSIZECHANGE',2048);
   define('AT_PARAGRAGH',4096);
   define('AT_CHANGE',8192);

function at_reset(&$at)
{
   $at = array(
	'flags' => 0,
	'font' => 0,
	'fcolor' => 'black',
	'bcolor' => 'white',
	'fontsize' => 3,
	'changecnt' => 0,
   );
}

function process_flags(&$at)
{
$fonts = array(
	"",
	"font-family: serif; white-space: normal; ",
	"font-family: monospace; white-space: normal; ",
	"font-family: monospace; white-space: pre; ",
	"font-family: fantasy; white-space: normal; ",
	"font-family: cursive; white-space: normal; "
);
   // font sizes 0-6
   $fontsizes = array(
  'xx-small','x-small','small','medium','large','x-large','xx-large'
   );
$out='';
if ($at['flags']&AT_CHANGE)
{
	$out = "<span style='".
		(($at['flags']&AT_ITALICS)?"font-style: italic; ":'').
		(($at['flags']&AT_BOLD)?"font-weight: bold; ":'').
		(($at['flags']&AT_SUPERS)?"vertical-align: top; font-size: 50%; ":'').
		(($at['flags']&AT_SUBS)?"vertical-align: bottom; font-size: 50%; ":'').
		(($at['flags']& (AT_UNDERLINE | AT_THROUGH | AT_OVERLINE | AT_BLINK))?("text-decoration: ". 
			(($at['flags'] & AT_UNDERLINE)?"underline ":'').
			(($at['flags'] & AT_THROUGH)?"line-through ":'').
			(($at['flags'] & AT_OVERLINE)?"overline ":'').
			(($at['flags'] & AT_BLINK)?"blink ":'').
			"; "):'').
		(($at['flags']&AT_FONTCHANGE)?$fonts[$at['font']]:'').
		(($at['flags']&AT_FONTSIZECHANGE)?("font-size: ".$fontsizes[$at['fontsize']]."; "):'').
		((($at['flags']&AT_FCOLORCHANGE)&&(!empty($at['fcolor'])))?("color: $at[fcolor]; "):'').
		((($at['flags']&AT_BCOLORCHANGE)&&(!empty($at['bcolor'])))?("background-color: $at[bcolor]; "):'').
		"'>";
		$at['flags'] ^= (AT_CHANGE | AT_FCOLORCHANGE | AT_BCOLORCHANGE | AT_FONTSIZECHANGE | AT_FONTCHANGE);
		$at['changecnt']++;
}
return $out;
}

function str_textcodes($strin)
{
   // dos colors to html colors
   $d2h_colors = array(
  '#000','#a00','#0a0','#a50','#00a','#a0a','#0aa','#aaa',
  '#555','#f55','#5f5','#ff5','#55f','#f5f','#5ff','#fff'
   );

   $justification = array(
				"left",
				"right",
				"justify",
				"center",
				"left; text-indent: 32px",
				"right; text-indent: 32px",
				"justify; text-indent: 32px",
				"center; text-indent: 32px",
				"left; padding-left: 32px");
   $specialchars= array('2591','2592','2593','2588','2580','2584','258c','2590','250c','252c','2510',
			  '251c','253c','2524','2514','2534','2518','2502','2500',);

   at_reset($at);
   $out='';
   $slen=strlen($strin);
   for($cpos=0;$cpos<$slen;$cpos++)
   {
	if($strin[$cpos]=='^')
	{
		switch($strin[++$cpos])
		{
			case '0':
				while($at['changecnt']--)
					$out .= "</span>";
				at_reset($at);
				break;
			case 'i':
				$at['flags'] |= AT_ITALICS | AT_CHANGE;
				break;
			case 'e':
				$at['flags'] |= AT_BOLD | AT_CHANGE;
				break;
			case 'u':
				$at['flags'] |= AT_UNDERLINE | AT_CHANGE;
				break;
			case 't':
				$at['flags'] |= AT_THROUGH | AT_CHANGE;
				break;
			case 'o':
				$at['flags'] |= AT_OVERLINE | AT_CHANGE;
				break;
			case 'x':
				$at['flags'] |= AT_BLINK | AT_CHANGE;
				break;
			case 'f':
				(($fn=strpos('pmcfs',$strin[++$cpos]))!==FALSE) && $at['font']=$fn+1;
				($fn!==FALSE) && $at['flags'] |= AT_FONTCHANGE | AT_CHANGE;
				break;
			case '~':
				$at['flags'] |= AT_SUPERS | AT_CHANGE;
				break;
			case '_':
				$at['flags'] |= AT_SUBS | AT_CHANGE;
				break;
			case 'r':
				$at['fcolor']^=$at['bcolor'];
				$at['bcolor']^=$at['fcolor'];
				$at['fcolor']^=$at['bcolor'];
				$at['flags'] |= AT_FCOLORCHANGE | AT_BCOLORCHANGE | AT_CHANGE;
				break;
			case 'c':
				$at['fcolor'] = $d2h_colors[hexdec($strin[++$cpos])];
				$at['flags'] |= AT_FCOLORCHANGE | AT_CHANGE;
				break;
			case 'b':
				$at['bcolor'] = $d2h_colors[hexdec($strin[++$cpos])];
				$at['flags'] |= AT_BCOLORCHANGE | AT_CHANGE;
				break;
			case 'C':
				$at['fcolor']='#'.strtoupper(substr($strin, ++$cpos, 6));
				$cpos+=5;
				$at['flags'] |= AT_FCOLORCHANGE | AT_CHANGE;
				break;
			case 'B':
				$at['bcolor']='#'.strtoupper(substr($strin, ++$cpos, 6));
				$cpos+=5;
				$at['flags'] |= AT_BCOLORCHANGE | AT_CHANGE;
				break;
			case 's':
				$s = $strin[++$cpos];
				$at['fontsize'] = (($s >= '0') && ($s <= '6'))?intval($s):3;
				$at['flags'] |= AT_FONTSIZECHANGE | AT_CHANGE;
				break;
			case 'p':
				$out .= (($at['flags'] & AT_PARAGRAGH)?'</P>':'') . '<P>';
				$at['flags'] |= AT_PARAGRAGH;
				break;
			case 'P':
				$out .= (($at['flags'] & AT_PARAGRAGH)?'</P>':'');
				$at['flags'] |= AT_PARAGRAGH;
				$out .='<P'. ((($fn=strpos('lrjcLRJCi',$strin[$cpos+1]))!==FALSE)?(" style='text-align: $justification[$fn];'"):'') .'>';
				($fn) && $cpos++;
				break;
			case 'n':
				$out .= "<br>";
				break;
			case 'g':
				$out .= process_flags($at);
				$out.=(($fn=strpos('0123tblrqweasdzxcvh',$strin[$cpos+1]))!==FALSE)?" &#x$specialchars[$fn];":' ';
				if($fn!==FALSE) $cpos++;
				break;
			case '^':
				$out.='^';
				break;
			}
   } else {
		$out .= process_flags($at) . $strin[$cpos];
   }
   }
   while($at['chnagecnt']--)
  $out .= "</span>";
   if ($at['flags']&AT_PARAGRAGH)
  $out .= '</P>';
   return $out;
}

$str = <<<EOS
^e^c1^s5TEXT CODES:^0 can be used in text messages, articles, and bulletins posted by users on the BBS.
^p^i^uRESET^0^n
^fm^^0^0 = Reset all attribute changes; clean slate; everything reset to defaults...
^p^i^uATTRIBUTES^0^n
^fm^^e^0 = ^eBold^0^n
^fm^^i^0 = ^iItalics^0^n
^fm^^u^0 = ^uUnderline^0^n
^fm^^t^0 = ^tStrike through^0^n
^fm^^o^0 = ^oOver-line^0^n
^fm^^x^0 = ^xBlink^0 (not supported on all browsers)
^p^i^uSCIENTIFIC^0^n
^fm^^~^0 = ^~Superscript^0 (These two are mutually exclusive)^n 
^fm^^_^0 = ^_Subscript^0
^p^i^uTYPE-FACES^0^n
^fm^^f^in^0 = Type-face font (dependent on browser) where ^i^fmn^0 = ^n
^Pi^fmp^0 ^fpproportional^0^n
^fmm^0 ^fmmonospaced^0^n
^fcc^0 ^fccode^0^n
^fcf^0 ^fffantasy^0^n
^fcs^0 ^fsscript^0^n
^p^i^uTYPE-FACE SIZING^0^n
^fm^^s#^0 = Change font size. (0=^s0smallest^0, 3=^s3normal^0 6=^s6largest^0)
^p^i^uCOLORING^0^n
^fm^^r^0 = ^rreverse^0. (swap foreground and background colors)^n
^fm^^C^i######^0 = change foreground color with hex (rrggbb) color.^n
^fm^^B^i######^0 = change background color with hex (rrggbb) color.^n
^fm^^c#^0 = change foreground color with quick color. (below)^n
^fm^^b^i#^0 = change background color with quick color. (below)^n
^Pi^fm0^0 ^c0Black^0^n
^fm1^0 ^c1Red^0^n
^fm2^0 ^c2Green^0^n
^fm3^0 ^c3Brown^0^n
^fm4^0 ^c4Blue^0^n
^fm5^0 ^c5Magenta^0^n
^fm6^0 ^c6Cyan^0^n
^fm7^0 ^b0^c7Light Gray^0^n
^fm8^0 ^c8Dark Gray^0^n
^fm9^0 ^b0^c9Bright Red^0^n
^fmA^0 ^b0^caBright Green^0^n
^fmB^0 ^b0^cbYellow^0^n
^fmC^0 ^b0^ccBright Blue^0^n
^fmD^0 ^b0^cdBright Magenta^0^n
^fmE^0 ^b0^ceBright Cyan^0^n
^fmF^0 ^b0^cfWhite^0
^p^i^uFORMATTING^0^n
^fm^^n^0 = new line^n
^fm^^p^0 = new paragraph^n
^fm^^P^ix^0 = new paragraph with justification/indentation.
^Pi^fml^0 left^n
^fmr^0 right^n
^fmc^0 center^n
^fmj^0 justify^n
^fmL^0 left w/indent^n
^fmR^0 right w/indent^n
^fmC^0 center w/indent^n
^fmJ^0 justify w/indent^n
^fmi^0 indent entire paragraph
^p^i^uSPECIAL CHARACTERS^0^n
^fm^^^^^0 = ^^^n
^fm^^g^in^0 = graphic character.  (not supported on all browsers) Where ^fm^in^0 =^n
^Pi^fm0^0 ^g0^n
^fm1^0 ^g1^n
^fm2^0 ^g2^n
^fm3^0 ^g3^n
^fmt^0 ^gt^n
^fmb^0 ^gb^n
^fml^0 ^gl^n
^fmr^0 ^gr^n
^fmq^0 ^gq^n
^fmw^0 ^gw^n
^fme^0 ^ge^n
^fma^0 ^ga^n
^fms^0 ^gs^n
^fmd^0 ^gd^n
^fmz^0 ^gz^n
^fmx^0 ^gx^n
^fmc^0 ^gc^n
^fmv^0 ^gv^n
^fmh^0 ^gh^n
^p
^fp^i^eThe above was generated with...^0^n
EOS;

   echo str_textcodes($str).'<br><br>';
   echo '<pre><code>'.$str.'</code></pre>';


?>

 

i moved some 2 pieces of code into their own functions, cutting the code significantly.

and opted for a strpos on the 2ndary code of some functions. using arrays for matching :) Which Cut out a lot of Code

changed the way the flags were being done, using bits instead of different variables, which cut out even more code.

 

Not shure on performance, ya may have to loop it 100-500 times to get  it profiled.

 

 

 

 

Link to comment
Share on other sites

When I went over the code, I do get a lot of what's going on.

and preg_match, may just overcomplicate the code u have already.

 

but we can still change some things around :)

...

i moved some 2 pieces of code into their own functions, cutting the code significantly.

and opted for a strpos on the 2ndary code of some functions. using arrays for matching :) Which Cut out a lot of Code

changed the way the flags were being done, using bits instead of different variables, which cut out even more code.

 

Not shure on performance, ya may have to loop it 100-500 times to get  it profiled.

 

Thanks everyone, I got it slimmed down quite abit running alot faster now.

 

Link to comment
Share on other sites

great, other optimizations ya may want to try and improve is the main for loop which goes character by character until it finds a control chracter.

ya can prolly use strpos, to find the next control character, than process a chunk of the text before. than adjust the pointer.

once ya start getting it slimmed down it shud be a lot more manageable

Link to comment
Share on other sites

great, other optimizations ya may want to try and improve is the main for loop which goes character by character until it finds a control chracter.

ya can prolly use strpos, to find the next control character, than process a chunk of the text before. than adjust the pointer.

once ya start getting it slimmed down it shud be a lot more manageable

 

That was part of my optimization. :)

 

...
         // skip ahead to next ^
         $j = strpos($strin, '^', $i);
         if ($j === FALSE)
         {
            // no more. out the rest.
            $out .= substr($strin, $i);
            $i = strlen($strin);
         }
         else
         {
            $out .= substr($strin, $i, $j - $i);
            $i = $j - 1;
         }
...

 

Cheers,

CW

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.