<?php
$str = 'Showing results [program=for {program} programs|No pogram at all] [province=in {province}] [degree=with degree of {degree}]';
function interpolateString($message, array $context = array()) {
$replace = array();
foreach ($context as $key => $val) {
$replace['{' . $key . '}'] = $val;
}
return strtr($message, $replace);
}
$arrContext = array(
'program' => 'Nursing',
'province' => 'Ontario',
'degree' => false
);
//echo interpolateString($str, $arrContext);
echo "\n";
$arrMatches = array();
preg_match_all("/\[(\w+)\=([^\[\]\|.*]*)?\|*([^\[\].*]*)\]/", $str, $arrMatches);
for ($i=0; $i<=count($arrMatches[1])-1;$i++) {
if ($arrContext[$arrMatches[1][$i]] !== false) {
$str = strstr($arrMatches[0][$i], $arrMatches[2][$i]
}else{
$str = strstr($arrMatches[0][$i], $arrMatches[2][$i];
}
}
echo $str;
- Output for 5.3.0 - 5.3.24, 5.4.0 - 5.4.15
- Parse error: syntax error, unexpected '}' in P8FtZ on line 26
Process exited with code 255. - Output for 5.3.25
- Parse error: syntax error, unexpected '}' in /in/P8FtZ on line 26
Process exited with code 255.
preferences:
183.8 ms | 1399 KiB | 49 Q