aboutsummaryrefslogtreecommitdiffstats
path: root/include/smarty/libs/plugins/shared.mb_str_replace.php
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2013-06-20 03:38:47 +0000
committerrvelices <rv-github@modusoptimus.com>2013-06-20 03:38:47 +0000
commit6fc07742f8fca9d32db23243d374ea27e8ee4c1e (patch)
treebc7240c53a1c6bdff6c785153deb6306585c4062 /include/smarty/libs/plugins/shared.mb_str_replace.php
parent9843eb362dd7d1b9d762871777ef76fa84e8202a (diff)
smarty 3 - first pass for tests
git-svn-id: http://piwigo.org/svn/trunk@23384 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/smarty/libs/plugins/shared.mb_str_replace.php')
-rw-r--r--include/smarty/libs/plugins/shared.mb_str_replace.php55
1 files changed, 55 insertions, 0 deletions
diff --git a/include/smarty/libs/plugins/shared.mb_str_replace.php b/include/smarty/libs/plugins/shared.mb_str_replace.php
new file mode 100644
index 000000000..ecafeb74a
--- /dev/null
+++ b/include/smarty/libs/plugins/shared.mb_str_replace.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Smarty shared plugin
+ *
+ * @package Smarty
+ * @subpackage PluginsShared
+ */
+if (!function_exists('smarty_mb_str_replace')) {
+
+ /**
+ * Multibyte string replace
+ *
+ * @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
+ * @return string replaced string
+ * @author Rodney Rehm
+ */
+ function smarty_mb_str_replace($search, $replace, $subject, &$count=0)
+ {
+ 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) {
+ $string = &smarty_mb_str_replace($search, $replace, $string, $c);
+ $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));
+ while ($n--) {
+ $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);
+ }
+ return $subject;
+ }
+
+}
+?> \ No newline at end of file