summaryrefslogtreecommitdiff
path: root/ext/standard/string.c
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2008-11-02 18:24:34 +0000
committerFelipe Pena <felipe@php.net>2008-11-02 18:24:34 +0000
commit8f12025b214c950ba2ad98d9634589659fd14ef2 (patch)
tree97f4de0915b41988046b704dbc30f830a9acac49 /ext/standard/string.c
parent3e543f246446e7eba4c0edb9936874949543334a (diff)
downloadphp-git-8f12025b214c950ba2ad98d9634589659fd14ef2.tar.gz
- MFH: Added str_getcsv()
Diffstat (limited to 'ext/standard/string.c')
-rw-r--r--ext/standard/string.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 81392f11d9..c2d7ddf21c 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -50,6 +50,9 @@
#include "TSRM.h"
#endif
+/* For str_getcsv() support */
+#include "ext/standard/file.h"
+
#define STR_PAD_LEFT 0
#define STR_PAD_RIGHT 1
#define STR_PAD_BOTH 2
@@ -4456,6 +4459,27 @@ reg_char:
}
/* }}} */
+/* {{{ proto array str_getcsv(string input[, string delimiter[, string enclosure[, string escape]]])
+Parse a CSV string into an array */
+PHP_FUNCTION(str_getcsv)
+{
+ char *str, delim = ',', enc = '"', esc = '\\';
+ char *delim_str = NULL, *enc_str = NULL, *esc_str = NULL;
+ int str_len = 0, delim_len = 0, enc_len = 0, esc_len = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sss", &str, &str_len, &delim_str, &delim_len,
+ &enc_str, &enc_len, &esc_str, &esc_len) == FAILURE) {
+ return;
+ }
+
+ delim = delim_len ? delim_str[0] : delim;
+ enc = enc_len ? enc_str[0] : enc;
+ esc = esc_len ? esc_str[0] : esc;
+
+ php_fgetcsv(NULL, delim, enc, esc, str_len, str, return_value TSRMLS_CC);
+}
+/* }}} */
+
/* {{{ proto string str_repeat(string input, int mult)
Returns the input string repeat mult times */
PHP_FUNCTION(str_repeat)