1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 5.1.6 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2011, 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 view,
37 * replacing them with the data in the second param
45 public function parse($template, $data, $return = FALSE)
47 $CI =& get_instance();
48 $template = $CI->load->view($template, $data, TRUE);
50 return $this->_parse($template, $data, $return);
53 // --------------------------------------------------------------------
58 * Parses pseudo-variables contained in the specified string,
59 * replacing them with the data in the second param
67 function parse_string($template, $data, $return = FALSE)
69 return $this->_parse($template, $data, $return);
72 // --------------------------------------------------------------------
77 * Parses pseudo-variables contained in the specified template,
78 * replacing them with the data in the second param
86 function _parse($template, $data, $return = FALSE)
93 foreach ($data as $key => $val)
97 $template = $this->_parse_pair($key, $val, $template);
101 $template = $this->_parse_single($key, (string)$val, $template);
105 if ($return == FALSE)
107 $CI =& get_instance();
108 $CI->output->append_output($template);
114 // --------------------------------------------------------------------
117 * Set the left/right variable delimiters
124 function set_delimiters($l = '{', $r = '}')
130 // --------------------------------------------------------------------
133 * Parse a single key/value
141 function _parse_single($key, $val, $string)
143 return str_replace($this->l_delim.$key.$this->r_delim, $val, $string);
146 // --------------------------------------------------------------------
151 * Parses tag pairs: {some_tag} string... {/some_tag}
159 function _parse_pair($variable, $data, $string)
161 if (FALSE === ($match = $this->_match_pair($string, $variable)))
167 foreach ($data as $row)
170 foreach ($row as $key => $val)
172 if ( ! is_array($val))
174 $temp = $this->_parse_single($key, $val, $temp);
178 $temp = $this->_parse_pair($key, $val, $temp);
185 return str_replace($match['0'], $str, $string);
188 // --------------------------------------------------------------------
191 * Matches a variable pair
198 function _match_pair($string, $variable)
200 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))
211 /* End of file Parser.php */
212 /* Location: ./system/libraries/Parser.php */