From 37a17acefc111516462bd103010ec5d660f876f1 Mon Sep 17 00:00:00 2001 From: fidian Date: Thu, 1 Feb 2001 13:05:56 +0000 Subject: [PATCH] Removed ereg and ereg_replace calls. Using simple string manipulation. This way we don't have to worry about what $needle is. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1030 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/strings.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/functions/strings.php b/functions/strings.php index 9b7371de..e3791452 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -6,10 +6,11 @@ //************************************************************************* // Count the number of occurances of $needle are in $haystack. + // $needle can be a character or string, and need not occur in $haystack //************************************************************************* function countCharInString($haystack, $needle) { - $haystack = ereg_replace("[^$needle]",'',$haystack); - return strlen($haystack); + if ($needle == '') return 0; + return count(explode($needle, $haystack)); } //************************************************************************* @@ -18,9 +19,13 @@ //************************************************************************* function readShortMailboxName($haystack, $needle) { if ($needle == '') return $haystack; - if ($needle == '.') $needle = '\\.'; - ereg("([^$needle]+)$needle?$", $haystack, $regs); - return $regs[1]; + $parts = explode($needle, $haystack); + $elem = array_pop($parts); + while ($elem == '' && count($parts)) + { + $elem = array_pop($parts); + } + return $elem; } //************************************************************************* @@ -28,9 +33,14 @@ // of the $haystack is reached. $needle is a single character //************************************************************************* function readMailboxParent($haystack, $needle) { - if ($needle == '.') $needle = '\\.'; - ereg("^(.+)$needle([^$needle]+)$needle?$", $haystack, $regs); - return $regs[1]; + if ($needle == '') return ''; + $parts = explode($needle, $haystack); + $elem = array_pop($parts); + while ($elem == '' && count($parts)) + { + $elem = array_pop($parts); + } + return join($needle, $parts); } // Searches for the next position in a string minus white space -- 2.25.1