Welcome Guest, Not a member yet? Register   Sign In
string parsing in between curly bracket
#14

[eluser]diZzyCoDeR[/eluser]
It's been a month, but maybe this will help others...

It *IS* indeed a great library, and it *DOES* come with a function to do what you're asking. I missed it completely until I was rifling through it to steal code to write myself a function that would simply convert the data stored in a variable
Code:
$content = '{foo} and {bar}';
to the values stored in
Code:
$foobar['foo'] = 'FOO';
$foobar['bar'] = 'BAR';

...then I saw it, parse_globals() -- which you could use on it's own, or part of the Simpletags library, as such:

Code:
$this->load->library('simpletags');

$output = $this->simpletags->parse_globals($content, $foobar);

thus, $output will evaluate to:
Quote:FOO and BAR

Code:
/**
* Parse Globals
*
* Parses global data tags.  These are tags that do not use a trigger
* and have a variable in the $data array.  This enables you to use
* globals inside of other tags:
*
* The Tag:
* {tag:blog:posts offset="{offset}"}
*
* The data array:
* array(
*     'offset' => $this->uri->segment(3),
* );
*
* @access    public
* @param    string    The content to parse
* @param    array    The globals
* @return    string    The parsed content
*/
public function parse_globals($content, $data)
{
        foreach ($data as $var => $value)
        {
                if ( ! is_array($value))
                {
                        $content = str_replace('{'.$var.'}', $value, $content);
                }
        }
        return $content;
}


Messages In This Thread
string parsing in between curly bracket - by El Forum - 01-04-2011, 07:08 PM
string parsing in between curly bracket - by El Forum - 01-04-2011, 08:35 PM
string parsing in between curly bracket - by El Forum - 01-04-2011, 08:44 PM
string parsing in between curly bracket - by El Forum - 01-04-2011, 08:59 PM
string parsing in between curly bracket - by El Forum - 01-04-2011, 09:07 PM
string parsing in between curly bracket - by El Forum - 01-04-2011, 09:16 PM
string parsing in between curly bracket - by El Forum - 01-04-2011, 09:25 PM
string parsing in between curly bracket - by El Forum - 01-04-2011, 09:33 PM
string parsing in between curly bracket - by El Forum - 01-04-2011, 10:16 PM
string parsing in between curly bracket - by El Forum - 01-05-2011, 01:57 AM
string parsing in between curly bracket - by El Forum - 01-05-2011, 02:00 AM
string parsing in between curly bracket - by El Forum - 01-05-2011, 05:06 AM
string parsing in between curly bracket - by El Forum - 01-06-2011, 01:09 AM
string parsing in between curly bracket - by El Forum - 02-16-2011, 08:19 PM
string parsing in between curly bracket - by El Forum - 02-16-2011, 10:25 PM
string parsing in between curly bracket - by El Forum - 02-18-2011, 07:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB