Welcome Guest, Not a member yet? Register   Sign In
Parse() and parse_string() what is the difference?
#1

[eluser]Unknown[/eluser]
To learn from you:
parse () and parse_string () what is the difference?Under what circumstances should use the parse_string method?Can you give me an example?Thank you very much.
#2

[eluser]PhilTem[/eluser]
Where did you find the parse() function?

A real PHP function is parse_string() and its docu can be found here

But I didn't find anything about parse() except for in the user's guide.
#3

[eluser]Unknown[/eluser]
The explanation in the manual, but I don't know if the $string = $this->parser->parse ('blog_template', $data, TRUE) role, its return value generally in what circumstances be used?While the $this->parser->parse_string () method and under what circumstances?


Quote:$this->parser->parse()

This method accepts a template name and data array as input, and it generates a parsed version. Example:
$this->load->library('parser');

$data = array(
'blog_title' => 'My Blog Title',
'blog_heading' => 'My Blog Heading'
);

$this->parser->parse('blog_template', $data);

The first parameter contains the name of the view file (in this example the file would be called blog_template.php), and the second parameter contains an associative array of data to be replaced in the template. In the above example, the template would contain two variables: {blog_title} and {blog_heading}

There is no need to "echo" or do something with the data returned by $this->parser->parse(). It is automatically passed to the output class to be sent to the browser. However, if you do want the data returned instead of sent to the output class you can pass TRUE (boolean) to the third parameter:
$string = $this->parser->parse('blog_template', $data, TRUE);

$this->parser->parse_string()

This method works exactly like parse(), only accepts a string as the first parameter in place of a view file.
#4

[eluser]Aken[/eluser]
parse() will parse the view file specified. parse_string() will parse the string that is specified. One uses a view file, the other uses a string that you supply.




Theme © iAndrew 2016 - Forum software by © MyBB