1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 4.3.2 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
16 // ------------------------------------------------------------------------
21 * @package CodeIgniter
22 * @subpackage Libraries
24 * @author ExpressionEngine Dev Team
25 * @link http://codeigniter.com/user_guide/libraries/parser.html
36 * Parses pseudo-variables contained in the specified template,
37 * replacing them with the data in the second param
45 function parse($template, $data, $return = FALSE)
47 $CI =& get_instance();
48 $template = $CI->load->view($template, $data, TRUE);
55 foreach ($data as $key => $val)
59 $template = $this->_parse_pair($key, $val, $template);
63 $template = $this->_parse_single($key, (string)$val, $template);
69 $CI->output->append_output($template);
75 // --------------------------------------------------------------------
78 * Set the left/right variable delimiters
85 function set_delimiters($l = '{', $r = '}')
91 // --------------------------------------------------------------------
94 * Parse a single key/value
102 function _parse_single($key, $val, $string)
104 return str_replace($this->l_delim.$key.$this->r_delim, $val, $string);
107 // --------------------------------------------------------------------
112 * Parses tag pairs: {some_tag} string... {/some_tag}
120 function _parse_pair($variable, $data, $string)
122 if (FALSE === ($match = $this->_match_pair($string, $variable)))
128 foreach ($data as $row)
131 foreach ($row as $key => $val)
133 if ( ! is_array($val))
135 $temp = $this->_parse_single($key, $val, $temp);
139 $temp = $this->_parse_pair($key, $val, $temp);
146 return str_replace($match['0'], $str, $string);
149 // --------------------------------------------------------------------
152 * Matches a variable pair
159 function _match_pair($string, $variable)
161 if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+?)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match))
172 /* End of file Parser.php */
173 /* Location: ./system/libraries/Parser.php */