]> git.mxchange.org Git - mailer.git/blobdiff - inc/wrapper-functions.php
Rewrote 2 str_replace() calls to one with array()
[mailer.git] / inc / wrapper-functions.php
index 89b6ed3c7688cc10fbbeb078a49ad81d26d7a6e3..e20a4abd2139350827cf4f5e69ec2794cb233cc5 100644 (file)
@@ -3502,7 +3502,7 @@ function shift_array (&$array, $value, $key = '0') {
 // Wrapper for str_pad() with left padding zeros
 function padLeftZero ($str, $amount = 2) {
        // Is str_pad() there?
-       if (function_exists('str_pad')) {
+       if (!function_exists('str_pad')) {
                // Use prependZeros()
                return prependZeros($str, $amount);
        } else {
@@ -3556,5 +3556,27 @@ function ifSubjectHasReferralSuffix ($subject) {
        return $GLOBALS[__FUNCTION__][$subject];
 }
 
+// Converts an API response to an associative array
+function convertApiResponseToArray ($responseString, $keyDelimiter, $valueDelimiter) {
+       // Explode for key delimiter
+       $keys = explode($keyDelimiter, $responseString);
+
+       // Init returned array and "walk" through all entries
+       $returned = array();
+       foreach ($keys as $keyValue) {
+               // Explode it
+               $parts = explode($valueDelimiter, $keyValue);
+
+               // Count must be 2
+               assert(count($parts) == 2);
+
+               // Then add both: 0=key, 1=value
+               $returned[sqlEscapeString($parts[0])] = sqlEscapeString($parts[1]);
+       } // END - if
+
+       // Return finished array
+       return $returned;
+}
+
 // [EOF]
 ?>