public function FrxSyntaxEngine::replace in Forena Reports 7.4
Same name and namespace in other branches
- 6.2 FrxSyntaxEngine.inc \FrxSyntaxEngine::replace()
- 6 FrxSyntaxEngine.inc \FrxSyntaxEngine::replace()
- 7 FrxSyntaxEngine.inc \FrxSyntaxEngine::replace()
- 7.2 FrxSyntaxEngine.inc \FrxSyntaxEngine::replace()
- 7.3 FrxSyntaxEngine.inc \FrxSyntaxEngine::replace()
Parameters
string $text: Text on which to perform token replacment.
bool $raw: TRUE implies data will not be formatted. Defaults to FALSE.
Return value
string Replaced text.
2 calls to FrxSyntaxEngine::replace()
- FrxSyntaxEngine::replaceNested in ./
FrxSyntaxEngine.inc - Replaces nested array data.
- FrxSyntaxEngine::test in ./
FrxSyntaxEngine.inc - Test for TRUE/FALSE for conditions that are able to be represented using bind parameters Note that | are used to separate the different conditions and these are to be OR'd together.
File
- ./
FrxSyntaxEngine.inc, line 87 - FrXSytnaxEngine defines how regular expression procesing/token substitution takes place. It includes support for passing in a formatter oobject that will escape strings properly before substituting them.
Class
- FrxSyntaxEngine
- @file FrXSytnaxEngine defines how regular expression procesing/token substitution takes place. It includes support for passing in a formatter oobject that will escape strings properly before substituting them.
Code
public function replace($text, $raw = FALSE) {
if (is_array($text)) {
foreach ($text as $key => $value) {
$text[$key] = $this
->replace($value, $raw);
}
return $text;
}
//Otherswise assume text
$match = array();
$o_text = $text;
// Put the data on the stack.
if (preg_match_all($this->tpattern, $o_text, $match)) {
// If we are replacing a single value then return exactly
// the single value in its native type;
$single_value = $match && count($match[0]) == 1 && $match[0][0] == $text && $raw;
foreach ($match[0] as $match_num => $token) {
$path = trim($token, $this->trim_chars);
$value = $this
->get_value($path, $raw);
if ($single_value) {
return $value;
}
else {
$pos = strpos($text, $token);
if ($pos !== FALSE) {
$text = substr_replace($text, $value, $pos, strlen($token));
}
}
}
}
return $text;
}