Location: PHPKode > scripts > MLdoc > mldoc/ML.class.php
<?php
Class MLdoc
{
  var $tags;
  
  function MLdoc( $open, $content = null, $close = null )
  {
    $this->open = $open;
    $this->content = $content;
    $this->close = $close;
  }

  function insert( $open, $content, $close )
  {
    $new_tag = new MLdoc( $open, $content, $close );
    if( $this->close == null )
    {
      die("invalid ML object");
    }
    $this->tags[] = $new_tag;
    return $new_tag;
  }

  function compose( $depth = 0, $indent_str = "\t", $newline_str = "\n" )
  {
    $indent = str_pad( "", $depth, $indent_str );
    
    $return_str .= $indent . $this->open . $newline_str;
    
    if( $this->close == null )
      return $return_str;

    if( $this->content != null)
      $return_str .= $indent . $indent_str . $this->content . $newline_str;

    if (is_array($this->tags))
    {
      $keys = array_keys($this->tags);
      foreach($keys as $key)
      {
        $return_str .= $this->tags[$key]->compose( $depth + 1, $indent_str );
      }
    }
    
    $return_str .= $indent . $this->close . $newline_str;

    return $return_str;
  }
}
?>
Return current item: MLdoc