[eluser]Rolly1971[/eluser]
I did a few searches through the forum and wiki and could not find anything like this.
I was in need of a way to parser CI 'template tags' from content stored in a database table, IE: {tagname}. So Not finding anything that matched what i was looking for i cloned one of the functions from the CI Parser and adjusted it to accept a string instead of requiring a path to a file.
If something like this is posted here already and i just missed or overlooked it, my apologies.
Anyway, here it is.
the MY_Parser.php file is attached, save this file in one of the following locations depending on the version of CI you are using:
for CI 1.7.2: ./application/libraries/MY_Parser.php
for CI 2.0 : ./application/core/MY_Parser.php
usage is exactly the same as using the CI Parser class, except you call the parse_db_string() function instead of parse(). IE:
Code:
$this->load->libarary('parser');
$content = $this->parser->parse_db_string('My page content, parsed by a {tag}', array('tag' => '<b>extended CI Parser Class</b>', TRUE);
like i mentioned i built this to parser tags typed into content stored in a database, so to use this in that manner, retrieve your database stored content, and pass it into this function, as if you were using the CI parser. But instead of a path to a file, you are passing in the content from the database instead. the output is identical to the ci parser function parse(), third parameter: TRUE to return a string, FALSE to output directly to browser.
Hopefully this will help someone out, or at least be useful to someone. Any questions, just post em and i will answer best i can.