2012-07-04 07:23:08 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Smarty shared plugin
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @package Smarty
|
2012-07-04 07:23:08 +02:00
|
|
|
* @subpackage PluginsShared
|
|
|
|
*/
|
|
|
|
if (!function_exists('smarty_mb_str_replace')) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Multibyte string replace
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @param string $search the string to be searched
|
|
|
|
* @param string $replace the replacement string
|
|
|
|
* @param string $subject the source string
|
|
|
|
* @param int &$count number of matches found
|
|
|
|
*
|
2012-07-04 07:23:08 +02:00
|
|
|
* @return string replaced string
|
|
|
|
* @author Rodney Rehm
|
|
|
|
*/
|
2014-09-07 13:38:28 +02:00
|
|
|
function smarty_mb_str_replace($search, $replace, $subject, &$count = 0)
|
2012-07-04 07:23:08 +02:00
|
|
|
{
|
|
|
|
if (!is_array($search) && is_array($replace)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (is_array($subject)) {
|
|
|
|
// call mb_replace for each single string in $subject
|
|
|
|
foreach ($subject as &$string) {
|
2014-09-07 13:38:28 +02:00
|
|
|
$string = & smarty_mb_str_replace($search, $replace, $string, $c);
|
2012-07-04 07:23:08 +02:00
|
|
|
$count += $c;
|
|
|
|
}
|
|
|
|
} elseif (is_array($search)) {
|
|
|
|
if (!is_array($replace)) {
|
|
|
|
foreach ($search as &$string) {
|
|
|
|
$subject = smarty_mb_str_replace($string, $replace, $subject, $c);
|
|
|
|
$count += $c;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$n = max(count($search), count($replace));
|
2014-09-07 13:38:28 +02:00
|
|
|
while ($n --) {
|
2012-07-04 07:23:08 +02:00
|
|
|
$subject = smarty_mb_str_replace(current($search), current($replace), $subject, $c);
|
|
|
|
$count += $c;
|
|
|
|
next($search);
|
|
|
|
next($replace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$parts = mb_split(preg_quote($search), $subject);
|
|
|
|
$count = count($parts) - 1;
|
|
|
|
$subject = implode($replace, $parts);
|
|
|
|
}
|
2014-09-07 13:38:28 +02:00
|
|
|
|
2012-07-04 07:23:08 +02:00
|
|
|
return $subject;
|
|
|
|
}
|
|
|
|
}
|