• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parse() and parse_string() what is the difference?

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.

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.

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?


This method accepts a template name and data array as input, and it generates a parsed version. Example:

$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 method works exactly like parse(), only accepts a string as the first parameter in place of a view file.

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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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