You are here

public static function PHPExcel_Calculation_TextData::SUBSTITUTE in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/TextData.php \PHPExcel_Calculation_TextData::SUBSTITUTE()

* SUBSTITUTE * *

Parameters

string $text Value: * @param string $fromText From Value * @param string $toText To Value * @param integer $instance Instance Number * @return string

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/TextData.php, line 517

Class

PHPExcel_Calculation_TextData
PHPExcel_Calculation_TextData

Code

public static function SUBSTITUTE($text = '', $fromText = '', $toText = '', $instance = 0) {
  $text = PHPExcel_Calculation_Functions::flattenSingleValue($text);
  $fromText = PHPExcel_Calculation_Functions::flattenSingleValue($fromText);
  $toText = PHPExcel_Calculation_Functions::flattenSingleValue($toText);
  $instance = floor(PHPExcel_Calculation_Functions::flattenSingleValue($instance));
  if ($instance == 0) {
    if (function_exists('mb_str_replace')) {
      return mb_str_replace($fromText, $toText, $text);
    }
    else {
      return str_replace($fromText, $toText, $text);
    }
  }
  else {
    $pos = -1;
    while ($instance > 0) {
      if (function_exists('mb_strpos')) {
        $pos = mb_strpos($text, $fromText, $pos + 1, 'UTF-8');
      }
      else {
        $pos = strpos($text, $fromText, $pos + 1);
      }
      if ($pos === false) {
        break;
      }
      --$instance;
    }
    if ($pos !== false) {
      if (function_exists('mb_strlen')) {
        return self::REPLACE($text, ++$pos, mb_strlen($fromText, 'UTF-8'), $toText);
      }
      else {
        return self::REPLACE($text, ++$pos, strlen($fromText), $toText);
      }
    }
  }
  return $text;
}