本文整理汇总了PHP中JString::str_replace方法的典型用法代码示例。如果您正苦于以下问题:PHP JString::str_replace方法的具体用法?PHP JString::str_replace怎么用?PHP JString::str_replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JString
的用法示例。
在下文中一共展示了JString::str_replace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: do_filter
protected function do_filter($var)
{
if (is_string($this->strings)) {
$this->strings = array($this->strings);
}
foreach ($this->strings as $word) {
// Check for custom replacement
$customReplacement = '';
if (JString::stristr($word, '=')) {
$tmp = explode('=', $word);
$customReplacement = JString::trim($tmp[1]);
$word = JString::trim($tmp[0]);
}
// $word = preg_replace('#[^A-Za-z0-9\*\$\^]#', '', JString::trim($word));
$replacement = '';
if (JString::stristr($word, '*') === false && JString::stristr($word, '$') === false && JString::stristr($word, '^') === false) {
$str = JString::strlen($word);
$first = $this->keep_first_last ? $word[0] : '';
$str = $this->keep_first_last ? $str - 2 : $str;
$last = $this->keep_first_last ? $word[JString::strlen($word) - 1] : '';
if ($customReplacement == '') {
$replacement = str_repeat('*', $str);
} else {
$replacement = $customReplacement;
}
if ($this->replace_matches_inside_words) {
$var = JString::str_replace($word, $first . $replacement . $last, $var);
} else {
$var = preg_replace('/\\b' . $word . '\\b/ui', $first . $replacement . $last, $var);
}
} else {
// Rebuiling the regex
$keySearch = array('/\\*/ms', '/\\$/ms');
$keyReplace = array('%', '#');
$word = preg_replace($keySearch, $keyReplace, $word);
$keySearch = array('/\\%/ms', '/\\#/ms');
$keyReplace = array('.?', '.*?');
$word = preg_replace($keySearch, $keyReplace, $word);
if ($customReplacement != '') {
$replacement = str_repeat('*', JString::strlen($word));
} else {
$replacement = $customReplacement;
}
$var = preg_replace('/\\b' . $word . '\\b/uims', $replacement, $var);
}
}
return $var;
}