<?

// function richtext($mytext, $inform)
function richtext($mytext,$breakon=false) {
  $tagflag = false;
  $mylen = strlen($mytext);
  $mylinelen = 0;
  $mylast = $mylen - 1;
  for ($i = 0; $i <= $mylast; $i++) {
    $mychar = substr($mytext,$i,1);
    if ($mychar == "[") {
      $tagflag = true;
    } else if ($mychar == "]") { 
      $mytag = strtolower($mytag);
      if ($mytag == "quote") {
        $myrich = $myrich."<i>\"";
      } else if ($mytag == "/quote") {
        $myrich = $myrich."\"</i>";
      }
      if ($mytag == "bold") {
        $myrich = $myrich."<b>";
      } else if ($mytag == "/bold") {
        $myrich = $myrich."</b>";
      }
      if ($mytag == "italic") {
        $myrich = $myrich."<i>";
      } else if ($mytag == "/italic") {
        $myrich = $myrich."</i>";
      }
      if ($mytag == "underline") {
        $myrich = $myrich."<u>";
      } else if ($mytag == "/underline") {
        $myrich = $myrich."</u>";
      }
      $mytag = "";
      $tagflag = false;
    } else {
      if ($tagflag == true) {
        $mytag = $mytag.$mychar;
      } else {
        $mylinelen++;
        if (ord($mychar) == 10) {
          // if ($inform == true) {}
          $myrich = $myrich."<br>";
          $mylinelen = 0;
          // echo "newline";
        } else {
          $myrich = $myrich.$mychar;
          if ($breakon==true) {
            if ($mylinelen>100) {
              $myrich = $myrich."<br>";
              $mylinelen = 0;
            }
          }
        }
      }
    }
  }
  return $myrich;
}

function rawtext($mytext) {
  $tagflag = false;
  $mylen = strlen($mytext);
  $mylast = $mylen - 1;
  for ($i = 0; $i <= $mylast; $i++) {
    $mychar = substr($mytext,$i,1);
    if ($mychar == "[") {
      $tagflag = true;
    } else if ($mychar == "]") { 
      $mytag = strtolower($mytag);
      $mytag = "";
      $tagflag = false;
    } else {
      if ($tagflag == true) {
        $mytag = $mytag.$mychar;
      } else {
        if (ord($mychar) == 10) {
          $myrich = $myrich."";
        } else {
          $myrich = $myrich.$mychar;
        }
      }
    }
  }
  return $myrich;
}


function hilittext($Text,$Needle) {
  for($j=0; $j< count($Needle); $j++){ 
    if ($Needle[$j] != "") { 
      $TextTemp = ""; 
      $i=0; 
      while($i<=strlen($Text)) {
        if((($i + strlen($Needle[$j])) <= strlen($Text)) && (strcasecmp($Needle[$j], substr($Text, $i, strlen($Needle[$j]))) == 0)) { 
          $TextTemp .= '[bold]' . substr($Text, $i , strlen($Needle[$j])) . '[/bold]';
          $i += strlen($Needle[$j]); 
        } else {  
          $TextTemp .= $Text{$i}; 
          $i++; 
        } 
      } 
      $Text = $TextTemp; 
      $TextTemp="";
    }
  } 
  return $Text; 
}

?>