12-21-2007, 09:46 PM
|
#6 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
|
Quote:
Originally Posted by Tanax
Can you explain this line?
PHP Code:
$replaced = preg_replace_callback('/\{([a-z0-9\.]+)\}/i', array($this, 'replace_callback'), $contents);
???
|
I'm assuming you understand regular expressions and I don't have to explain that part..
What that line does is that it searches for all occurrences of {([a-z0-9\.]+)} within the template file (which contents are in $contents) and then parses the matched string to $this->replace_callback.
Then the replace_callback method gets a string eg. "user.posts.count". It then "explodes" that string by each occurrence of "." so we get an array which looks something like this:
PHP Code:
Array
(
[0] => user
[1] => posts
[2] => count
)
And then it selects the correct data from the array(the second argument of the parse method) and returns it to the preg_replace_callback method, which in turn replaces the matched string by the returned data in the $contents string.
I recommend that you read the php site..
|
|
|
|