Jump to content

How Do I... (Mini Template Engine)


mattd8752

Recommended Posts

I am designing a Mini Template Engine with my site.  Anyway, I've got the code:

<?php
function bbcode($code){
$array=array(
"[b]" => "<b>",  //This sets the value of [b] to <b> so if you looked under [b] in the array you would find <b>.
"[/b]" => "</b>",

"[i]" => "<i>",
"[/i]" => "</i>",

"[u]" => "<u>",
"[/u]" => "</u>",

"[h1]" => "<h1>",
"[/h1]" => "</h1>",
"[img]" => "<img src=\"",
"[/img]" => "\" alt=\"\">",
"[url=\"" => "<a href=\"",
"\"]" => "\">",
"[/url]" => "</a>",
"[div class=\"" => "<div class=\"",
"[/div]" => "</div>",
);

$newtext = str_replace(array_keys($array), array_values($array), $code);
return $newtext;
}

function parse($file){
$content = file($file);
$type = explode("]", $content[0]);
$type = explode("[", $type[0]);
$type = $type[1];



$author = explode(":", $content[1]);
  if($author[1] == "Author"){
  $disp = $author[0];
    if($disp = "yes"){
    $author = $author[2];
    }else{
    $author = "0";
    }
  }else{
  die("Error in the AUTHOR code.  Please check your formatting and ensure that you use our sample template.  If you continue experiencing this issue, please post on our support forums.");
  }



$title = explode(":", $content[2]);
  if($title[0] == "Title"){
  $title = $title[1];
  }else{
  die("Error in the AUTHOR code.  Please check your formatting and ensure that you use our sample template.  If you continue experiencing this issue, please post on our support forums.");
  }

$size = count($content);

$i=3;
$main = "";
  while ($i < $size) {

    if($function != "scripting"){
      if(trim($content[$i]) == "{script}"){
      $function = "scripting";
      $line = 0;
      }else{
      $main .= $content[$i]."<br />\n";
      }

    }else{
    $linec = explode("-", $content[$i]);
      if($linec[0] == "File"){
      $inc = $linec[1];
      $handle = fopen(trim($inc), "rb");
        while (!feof($handle)) {
        $main .= fread($handle, 8192);
        }
      fclose($handle);
      }elseif(trim($content[$i]) == "{/script}"){
      $function = "regular";
      }
    }
  $i++;
  }
$main = bbcode($main);


//$q = "SELECT * FROM themes WHERE type = '".$type."'";
//$q=mysql_query($q);
//$rows=mysql_num_rows($q);
//  if($rows > 1){
//  die("Error, there is more than one template with the name: ".$type.".  Please delete one or select a different template.");
//  }
//$css=mysql_result($result,0,"location");
//$notice=mysql_result($result,0,"notice");
$css = "";
$notice = "";
$output = "<html>\n";
$output .= "<head>\n";
$output .= "<title>".$title."</title>\n";
$output .= "<LINK href=\"".$css."\" rel=\"stylesheet\" type=\"text/css\">\n";
$output .= "</head>\n";
$output .= "<body>\n";
$output .= $main;
$output .= "</body>\n";
$output .= "</html>";
return $output;
}

?>

What I want is to have the <br /> Not appear after DIVs (and other SPECIFIED BBcodes, not all).

 

Maybe if there is a way to check if the line trimmed ends with ].  Any help would be appreciated.  Feel free to take a copy of this script if you like it.

Link to comment
Share on other sites

"What I want is to have the

Not appear after DIVs (and other SPECIFIED BBcodes, not all)."

 

It's hard to help because it's not clear what you want.

 

"Maybe if there is a way to check if the line trimmed ends with ]"

 

Check out substr, strrpos, etc.

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.