First off, here is the function for reference:
function parseChunk($chunkName, $chunkArr, $prefix= "{", $suffix= "}") {
if (!is_array($chunkArr)) {
return false;
}
$chunk= $this->getChunk($chunkName);
foreach ($chunkArr as $key => $value) {
$chunk= str_replace($prefix . $key . $suffix, $value, $chunk);
}
return $chunk;
}
There are several reasons why it is not used in Ditto:
1. str_replace can replace an array of values with an array of values which is much faster than doing it in your own foreach loop (less function calls)
2. If you ever have a placeholder set to the number 0 or no value (unless this bug has been fixed since I last checked) the parser will show the same result in more than one iteration
3. A chunk name will not always be provided to Ditto as the tpl parameter can now include HTML via @CODE: or a file via @FILE:
This is the function Ditto uses:
function replace( $placeholders, $tpl ) {
return str_replace( array_keys( $placeholders ), array_values( $placeholders ), $tpl );
}
(I feel like I am saying the code sucks... which it doesn’t)