You are here

public function FrxSyntaxEngine::replace in Forena Reports 7.3

Same name and namespace in other branches
  1. 6.2 FrxSyntaxEngine.inc \FrxSyntaxEngine::replace()
  2. 6 FrxSyntaxEngine.inc \FrxSyntaxEngine::replace()
  3. 7 FrxSyntaxEngine.inc \FrxSyntaxEngine::replace()
  4. 7.2 FrxSyntaxEngine.inc \FrxSyntaxEngine::replace()
  5. 7.4 FrxSyntaxEngine.inc \FrxSyntaxEngine::replace()

Parameters

$text text that needs replacing:

$data:

Return value

unknown_type

1 call to FrxSyntaxEngine::replace()
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 72
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;

    //list($params) = $match[1];
    $i = 0;
    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;
}