2 /*------------------------------------------------------------
3 * CarbonPHP framework (C) Tom Bell
4 * http://tombell.org.uk
5 *------------------------------------------------------------*/
7 if (!defined('CARBON_PATH'))
9 exit('Direct script access is not allowed.');
14 protected $l_delim = '{';
15 protected $r_delim = '}';
18 public function __construct()
20 log_message('debug', 'Parser.php - Carbon_Parser class initialised');
23 public function parse($template, $data, $return = false)
25 $carbon =& get_instance();
26 $template = $carbon->load
->view($template, $data, true);
33 foreach ($data as $key => $value)
37 $template = $this->_parse_pair($key, $value, $template);
41 $template = $this->_parse_single($key, (string) $value, $template);
47 $carbon->output
->set_final_output($template);
53 public function set_delimiters($l = '{', $r = '}')
59 protected _parse_single($key, $value, $string)
61 return str_replace($this->l_delim
. $key . $this->r_delim
, $value, $string);
64 protected _parse_pair($variable, $data, $string)
66 $match = $this->_match_pair($string, $variable);
75 foreach ($data as $row)
79 foreach ($row as $key => $value)
83 $temp = $this->_parse_pair($key, $value, $temp);
87 $temp = $this->_parse_single($key, $value, $temp);
94 return str_replace($match['0'], $str, $string);
97 protected _match_pair($string, $variable)
99 if (!preg_match("|".$this->l_delim
. $variable . $this->r_delim
."(.+)".$this->l_delim
. '/' . $variable . $this->r_delim
."|s", $string, $match))