Replace all needles found in str with rewrites
@param Array[needle, rewrite]
@param string $str
@return string $str
962946
public static function strFindAndReplaceAll($vars = array(), $str)
    {
        if (array_count_values($vars) > 0){
            foreach ($vars as $key => $val) {
                for ($i = substr_count($str, $key); $i > 0; $i--) {
                    $str = \WebCMS\Helpers\SystemHelper::strlReplace($key, $val, $str);
                }
            }
        }
        return $str;
    }
1025762
public static function stripPostNewlineTabs(string $str): string
    {
        $regex = "~".PHP_EOL."[\t]+~";
        return preg_replace($regex, PHP_EOL, $str);
    }
1147607
public static function str_template_replace($str, $array)
    {
        if (!is_array($array)) {
            return $str;
        }
        foreach ($array as $key => $value) {
            $str = str_replace("{{$key}}",$value,$str);
        }
        return $str;
    }
1195635
public static function trimSpaceInStr($str)
    {
        $pat = array(" ", "　", "\t", "\n", "\r");
        $string = array("", "", "", "", "", );
        return str_replace($pat, $string, $str);
    }
1275421
public static function webappPrefixTooShort(string $str)
    {
        $length = strlen($str);
        if ($length === 0) {
            return new self(sprintf(
                'The WebApp Prefix must be at least 3 characters. You supplied an empty Prefix.'
            ));
        } else {
            return new self(sprintf(
                'The WebApp Prefix must be at least 3 characters. You supplied a %s character Prefix: %s',
                $length,
                $str
            ));
        }
    }
492135
static function strfilter($str)
    {
        $str = str_replace(' ', '_', $str);

        $str = strip_tags($str);

        $str = htmlspecialchars($str);

        return $str;
    }
855707
protected function modifyPath(string $str): string
    {
        return (string) $this->filterSegment($str)->withExtension($this->extension);
    }
1289280
public function limtitLines($str, $lines = 1)
    {
        $line = "\n";
        for ($i=2; $i<=$lines; $i++) {
            $line .= "\n";
        }
        return preg_replace("/[\r\n]+/", "$line", $str);
    }
1021272
protected function modifyQuery(string $str): string
    {
        return (string) $this->filterQuery($str)->append($this->query);
    }
506859
private static function IsValidReplacementString( $str )
	{
		// $charArr = explode( "", $str);
		for ( $k = 0; $k < strlen( $str ); $k++ )
		{
		    if ( $str[ $k ] == '\\' )
		    {
			   if ( $k < strlen( $str ) - 1 && ( $str[ $k + 1 ] == '\\' || $str[ $k + 1 ] == '$' ) )
				  $k++;
			   else
				  return false;
		    }
		    if ( $str[ $k ] == '$' )
		    {
			   if ( $k < strlen( $str ) - 1 && is_numeric( $str[ $k + 1 ] ) )
				  $k++;
			   else
				  return false;
		    }
		}
		return true;
	}
276133
public static function stripAll($str)
    {
        $str = stripslashes($str);
        $str = strip_tags($str);
        $str = \sb\Strings::unicodeUrldecode($str);
        $str = self::stripBling($str);
        $str = \sb\Strings::stripMicrosoftChars($str);
        return $str;
    }
457449
protected function _replaceAttrLinks($file, $str)
    {
        return preg_replace_callback('#(\s+(?:href|src|data-src|action)=["\'])([\w-/:.]+)#', function ($match) use ($file) {
            return $match[1] . $this->_completeRelativeLinks($file, $match[2]);
        }, $str);
    }
146785
protected function _replaceData($str, $data) {
		// Supported tags.
		$tags = array(
			'[__]' => '[/__]', '[__d]' => '[/__d]', '[__c]' => '[/__c]', '[php]' => '[/php]', '[currency]' => '[/currency]',
			'[url]' => '[/url]', '[image]' => '[/image]', '[link]' => '[/link]', '[truncate]' => '[/truncate]', '[time]' => '[/time]'
		);

		// Find all array path (i.e. [Post.title], [Comment.{n}.text], [Roles.{n, }.name]) matches.
		if (!preg_match_all('/\[([A-Za-z0-9_{},\s\.]+)\]/iUs', $str, $matches)) {
			return $str;
		}

		foreach ($matches[0] as $i => $match) {
			// Skip when exact match of other tag.
			if (in_array($match, $tags) || isset($tags[$match])) {
				continue;
			}

			// Skip when matches tag with attributes (i.e. [truncate length=10]).
			$continue = false;
			foreach (array_keys($tags) as $needle) {
				if ($continue = strpos($match, substr($needle, 0, -1)) === 0) {
					break;
				}
			}
			if ($continue) {
				continue;
			}

			// Check if {f} or {l} in array path.
			// @todo Write tests.
			preg_match('/\{([fl])\}/iUs', $matches[1][$i], $el);

			if (!empty($el)) {
				$matches[1][$i] = str_replace('{' . $el[1] . '}', '{n}', $matches[1][$i]);

				if ('l' == $el[1]) {
					$replace = array_pop(Hash::extract($data, $matches[1][$i]));
				} else if ('f' == $el[1]) {
					$replace = array_shift(Hash::extract($data, $matches[1][$i]));
				}

				$str = str_replace($match, $replace, $str);
				continue;
			}

			// Check if {n} or {s} in array path.
			preg_match('/\{[ns](.+)\}/iUs', $matches[1][$i], $glue);

			// Set string to use in `implode()` extract results.
			if (empty($glue[1])) {
				$glue[1] = ' ';
			} else {
				$matches[1][$i] = str_replace($glue[0], substr($glue[0], 0, 2) . '}', $matches[1][$i]);
			}

			// Replace.
			$str = str_replace($match, implode($glue[1], Hash::extract($data, trim($matches[1][$i]))), $str);
		}

		return $str;
	}
1182403
public static function strrev($str)
    {
        $result = '';
        $strLen = static::length($str);

        if (!$strLen) {
            return $result;
        }

        for ($i = $strLen - 1; $i >= 0; $i--) {
            $result .= static::substr($str, $i, 1);
        }

        return $result;
    }
130806
private function cleanInputData($str) {
        if (is_array($str)) {
            $new_array = [];
            foreach ($str as $key => $val) {
                $new_array [ $this->cleanInputKeys($key) ] = $this->cleanInputData($val);
            }

            return $new_array;
        }
        $str = self::$xss_cleaner->xss_clean($str);
        // Standardize newlines
        if (strpos($str, "\r") !== false) {
            $str = str_replace(["\r\n", "\r"], "\n", $str);
        }

        return $str;
    }
227798
public static function stringStartsWith($str, $prefix)
    {
        if(is_array($prefix)){
            foreach($prefix as $p){
                if($p === "" || strpos($str, $p) === 0){
                    return true;
                };
            }
            return false;
        }
        return $prefix === "" || strpos($str, $prefix) === 0;
    }
1207424
protected function _replaceCurrency($str) {
		if (!preg_match_all('/\[currency(.*?)\](.*)\[\/currency\]/i', $str, $matches)) {
			// Fallback regex for when no options are passed.
			if (!preg_match_all('/\[currency(.*?)\](.[^\[]*)\[\/currency\]/i', $str, $matches)) {
				return $str;
			}
		}

		foreach ($matches[0] as $i => $find) {
			$opts = $this->_extractAttributes(trim($matches[1][$i]));

			$currency = CakeNumber::defaultCurrency();
			if (isset($opts['currency'])) {
				$currency = $opts['currency'];
				unset($opts['currency']);
			}

			$replace = (empty($matches[2][$i]) || !is_numeric($matches[2][$i])) ? '' : CakeNumber::currency($matches[2][$i], $currency, $opts);
			$str = str_replace($find, $replace, $str);
		}

		return $str;
	}