Can anyone explain line 70? Why do we preg match between {….} . What is the significants of the { }
Maybe I am just using the system in a way that it was not intended. However I know I have not been the only one plagued by this.
Issue is on line 70
if (preg_match_all('~\{(.*?)\}~', $v, $matches, PREG_SET_ORDER)) {
I am sure there must be a reason for the {..} , however this causes a json string that is all on a single line to get messed up when written to cache array because the { MATCHING } implodes the json string (for lack of a better definition). If the match was on [[ .. ]] I get it but not {..}
The only solution thus far has been to make sure the json string is fully formatted with \n so that { is always followed by \n. However this is not an option when the json is created by encoding an array.
I have tested a confirmed a working solution .. though I am sure a regExpert would know how to write but not I.
My solution is to skip if json , but not knowing the significants of the whole preg_match {} I am not sure if I am breaking anything
$v= $setting->get('value');
if(!json_decode($v)){ /* <-- ADDED JSON CHECK */
$matches = array();
if (preg_match_all('~\{(.*?)\}~', $v, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
if (array_key_exists("{$match[1]}", $contextConfig)) {
$matchValue= $contextConfig["{$match[1]}"];
} else {
$matchValue= '';
}
$v= str_replace($match[0], $matchValue, $v);
}
}
} else { /*its json string do nothing */ }
$results['config'][$k]= $v;
[ed. note: aesmith last edited this post 12 years, 6 months ago.]