iliaa           Fri Feb  7 16:36:18 2003 EDT

  Modified files:              
    /php4/ext/standard  string.c php_string.h basic_functions.c 
  Log:
  Added str_split() function. This function can be used to break down a 
  string into an array.
  
  
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.353 php4/ext/standard/string.c:1.354
--- php4/ext/standard/string.c:1.353    Thu Jan 30 15:09:19 2003
+++ php4/ext/standard/string.c  Fri Feb  7 16:36:18 2003
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: string.c,v 1.353 2003/01/30 20:09:19 pollita Exp $ */
+/* $Id: string.c,v 1.354 2003/02/07 21:36:18 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -37,6 +37,9 @@
 #ifdef HAVE_MONETARY_H
 # include <monetary.h>
 #endif
+
+#include <math.h>
+
 #include "scanf.h"
 #include "zend_API.h"
 #include "zend_execute.h"
@@ -4296,9 +4299,43 @@
 
        RETURN_STRINGL(erealloc(str, str_len + 1), str_len, 0);
 }
-
 /* }}} */
 #endif
+
+/* {{{ proto array str_split(string str [, int split_length])
+   Convert a string to an array. If split_length is specified, break the string down 
+into chunks each split_length characters long. */
+PHP_FUNCTION(str_split) {
+       char *str;
+       int str_len;
+       long split_length = 1;
+       char *p;
+       int n_reg_segments;
+       
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, 
+&split_length) == FAILURE) {
+               return;
+       }
+
+       if (split_length <= 0) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "The the length of each 
+segment must be greater then zero.");
+               RETURN_FALSE;
+       }
+
+       array_init(return_value);
+
+       n_reg_segments = floor(str_len / split_length);
+       p = str;
+
+       while (n_reg_segments-- > 0) {
+               add_next_index_stringl(return_value, p, split_length, 1);
+               p += split_length;
+       }
+
+       if (p != (str + str_len)) {
+               add_next_index_stringl(return_value, p, (str + str_len - p), 1);
+       }
+}
+/* }}} */
+
 
 /*
  * Local variables:
Index: php4/ext/standard/php_string.h
diff -u php4/ext/standard/php_string.h:1.69 php4/ext/standard/php_string.h:1.70
--- php4/ext/standard/php_string.h:1.69 Thu Jan 30 00:00:40 2003
+++ php4/ext/standard/php_string.h      Fri Feb  7 16:36:18 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_string.h,v 1.69 2003/01/30 05:00:40 pollita Exp $ */
+/* $Id: php_string.h,v 1.70 2003/02/07 21:36:18 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */
 
@@ -87,6 +87,7 @@
 PHP_FUNCTION(sscanf);
 PHP_FUNCTION(str_shuffle);
 PHP_FUNCTION(str_word_count);
+PHP_FUNCTION(str_split);
 #ifdef HAVE_STRCOLL
 PHP_FUNCTION(strcoll);
 #endif
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.572 
php4/ext/standard/basic_functions.c:1.573
--- php4/ext/standard/basic_functions.c:1.572   Fri Feb  7 16:33:35 2003
+++ php4/ext/standard/basic_functions.c Fri Feb  7 16:36:18 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.572 2003/02/07 21:33:35 iliaa Exp $ */
+/* $Id: basic_functions.c,v 1.573 2003/02/07 21:36:18 iliaa Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -342,6 +342,7 @@
        PHP_FE(strrchr,                                                                
                                                 NULL)
        PHP_FE(str_shuffle,                                                            
                                                         NULL)
        PHP_FE(str_word_count,                                                         
                                                 NULL)
+       PHP_FE(str_split,                                                              
+                                                 NULL)
 
 #ifdef HAVE_STRCOLL
        PHP_FE(strcoll,                                                                
                                                 NULL)



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to