• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parser Library

#1
[eluser]Captain_Fluffy_Pants[/eluser]
So I was wondering if in
Code:
system/library/parser.php
if there was any configurations that i needed to do to make it work
Code:
class CI_Parser {

var $l_delim = '{';
var $r_delim = '}';
var $object;


public function parse($template, $data, $return = FALSE)
{
  $CI =& get_instance();
  $template = $CI->load->view($template, $data, TRUE);

  return $this->_parse($template, $data, $return);
}

// --------------------------------------------------------------------


function parse_string($template, $data, $return = FALSE)
{
  return $this->_parse($template, $data, $return);
}

// --------------------------------------------------------------------


function _parse($template, $data, $return = FALSE)
{
  if ($template == '')
  {
   return FALSE;
  }

  foreach ($data as $key => $val)
  {
   if (is_array($val))
   {
    $template = $this->_parse_pair($key, $val, $template);
   }
   else
   {
    $template = $this->_parse_single($key, (string)$val, $template);
   }
  }

  if ($return == FALSE)
  {
   $CI =& get_instance();
   $CI->output->append_output($template);
  }

  return $template;
}

// --------------------------------------------------------------------


function set_delimiters($l = '{', $r = '}')
{
  $this->l_delim = $l;
  $this->r_delim = $r;
}

// --------------------------------------------------------------------


function _parse_single($key, $val, $string)
{
  return str_replace($this->l_delim.$key.$this->r_delim, $val, $string);
}

// --------------------------------------------------------------------

function _parse_pair($variable, $data, $string)
{
  if (FALSE === ($match = $this->_match_pair($string, $variable)))
  {
   return $string;
  }

  $str = '';
  foreach ($data as $row)
  {
   $temp = $match['1'];
   foreach ($row as $key => $val)
   {
    if ( ! is_array($val))
    {
     $temp = $this->_parse_single($key, $val, $temp);
    }
    else
    {
     $temp = $this->_parse_pair($key, $val, $temp);
    }
   }

   $str .= $temp;
  }

  return str_replace($match['0'], $str, $string);
}

// --------------------------------------------------------------------

function _match_pair($string, $variable)
{
  if ( ! preg_match("|" . preg_quote($this->l_delim) . $variable . preg_quote($this->r_delim) . "(.+?)". preg_quote($this->l_delim) . '/' . $variable . preg_quote($this->r_delim) . "|s", $string, $match))
  {
   return FALSE;
  }

  return $match;
}

}
Would I have to change any of true or false to make it work properly Sad please help?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.