ZEND_ARG_INFO(0, str)
ZEND_END_ARG_INFO()
/* }}} */
+/* {{{ quot_print.c */
+static
+ZEND_BEGIN_ARG_INFO(arginfo_quoted_printable_encode, 0)
+ ZEND_ARG_INFO(0, str)
+ZEND_END_ARG_INFO()
+/* }}} */
/* {{{ rand.c */
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_srand, 0, 0, 0)
#endif
PHP_FE(quoted_printable_decode, arginfo_quoted_printable_decode)
+ PHP_FE(quoted_printable_encode, arginfo_quoted_printable_encode)
PHP_FE(convert_cyr_string, arginfo_convert_cyr_string)
PHP_FE(get_current_user, arginfo_get_current_user)
PHP_FE(set_time_limit, arginfo_set_time_limit)
}
/* }}} */
+#define PHP_QPRINT_MAXL 75
+
+PHPAPI unsigned char *php_quot_print_encode(const unsigned char *str, size_t length, size_t *ret_length) /* {{{ */
+{
+ unsigned long lp = 0;
+ unsigned char c, *ret, *d;
+ char *hex = "0123456789ABCDEF";
+
+ ret = safe_emalloc(1, 3 * length + 3 * (((3 * length)/PHP_QPRINT_MAXL) + 1), 0);
+ d = ret;
+
+ while (length--) {
+ if (((c = *str++) == '\015') && (*str == '\012') && length > 0) {
+ *d++ = '\015';
+ *d++ = *str++;
+ length--;
+ lp = 0;
+ } else {
+ if (iscntrl (c) || (c == 0x7f) || (c & 0x80) || (c == '=') || ((c == ' ') && (*str == '\015'))) {
+ if ((lp += 3) > PHP_QPRINT_MAXL) {
+ *d++ = '=';
+ *d++ = '\015';
+ *d++ = '\012';
+ lp = 3;
+ }
+ *d++ = '=';
+ *d++ = hex[c >> 4];
+ *d++ = hex[c & 0xf];
+ } else {
+ if ((++lp) > PHP_QPRINT_MAXL) {
+ *d++ = '=';
+ *d++ = '\015';
+ *d++ = '\012';
+ lp = 1;
+ }
+ *d++ = c;
+ }
+ }
+ }
+ *d = '\0';
+ *ret_length = d - ret;
+
+ ret = erealloc(ret, *ret_length + 1);
+ return ret;
+}
+/* }}} */
+
/*
*
* Decoding Quoted-printable string.
}
/* }}} */
+/* {{{ proto string quoted_printable_encode(string str) U */
+PHP_FUNCTION(quoted_printable_encode)
+{
+ char *str, *new_str;
+ int str_len;
+ size_t new_str_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) != SUCCESS) {
+ return;
+ }
+
+ if (!str_len) {
+ RETURN_EMPTY_STRING();
+ }
+
+ new_str = (char *)php_quot_print_encode((unsigned char *)str, (size_t)str_len, &new_str_len);
+ RETURN_STRINGL(new_str, new_str_len, 0);
+}
+/* }}} */
+
/*
* Local variables:
* tab-width: 4
#define QUOT_PRINT_H
PHPAPI unsigned char *php_quot_print_decode(const unsigned char *str, size_t length, size_t *ret_length, int replace_us_by_ws);
+PHPAPI unsigned char *php_quot_print_encode(const unsigned char *str, size_t length, size_t *ret_length);
PHP_FUNCTION(quoted_printable_decode);
+PHP_FUNCTION(quoted_printable_encode);
#endif /* QUOT_PRINT_H */
--- /dev/null
+--TEST--
+quoted_printable_encode() tests - 1
+--FILE--
+<?php
+
+var_dump(quoted_printable_encode());
+var_dump(quoted_printable_encode(""));
+var_dump(quoted_printable_encode("test"));
+var_dump(quoted_printable_encode("test", "more"));
+
+$a = array("str");
+var_dump(quoted_printable_encode($a));
+var_dump(quoted_printable_encode(1));
+var_dump(quoted_printable_encode(NULL));
+var_dump(quoted_printable_encode(false));
+
+echo "Done\n";
+?>
+--EXPECTF--
+Warning: quoted_printable_encode() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+string(0) ""
+string(4) "test"
+
+Warning: quoted_printable_encode() expects exactly 1 parameter, 2 given in %s on line %d
+NULL
+
+Warning: quoted_printable_encode() expects parameter 1 to be binary string, array given in %s on line %d
+NULL
+string(1) "1"
+string(0) ""
+string(0) ""
+Done