Date: 05/20/00
- Next message: Bug Database: "[PHP-DEV] Bug #3922 Updated: == bug"
- Previous message: Manuel Lemos: "Re: [PHP-DEV] Re: [PHP4BETA] PHP 4.0.0 Release packaged"
- Next in thread: Bug Database: "[PHP-DEV] PHP 4.0 Bug #3251 Updated: 3rd arg to explode, (same 3rd arg that split() has)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
ID: 3251
Updated by: hholzgra
Reported By: tom <email protected>
Status: Suspended
Bug Type: Feature/Change Request
Assigned To: hholzgra
Comments:
suspended 'till after release
patch:
--- ext/standard/php_string.h 2000/04/26 00:29:59 1.12
+++ ext/standard/php_string.h 2000/05/19 22:00:38 1.13
@@ -109,7 +109,7 @@
PHPAPI void php_char_to_str(char *str, uint len, char from, char *to, int to_len, pval *result);
PHPAPI void php_implode(pval *delim, pval *arr, pval *return_value);
-PHPAPI void php_explode(pval *delim, pval *str, pval *return_value);
+PHPAPI void php_explode(pval *delim, pval *str, pval *return_value, int limit);
PHPAPI inline char *php_memnstr(char *haystack, char *needle, int needle_len, char *end);
PHPAPI size_t php_strspn(char *s1, char *s2, char *s1_end, char *s2_end);
PHPAPI size_t php_strcspn(char *s1, char *s2, char *s1_end, char *s2_end);
--- ext/standard/string.c 2000/05/18 15:34:35 1.110
+++ ext/standard/string.c 2000/05/19 22:00:38 1.111
@@ -213,7 +213,7 @@
}
/* }}} */
-PHPAPI void php_explode(zval *delim, zval *str, zval *return_value)
+PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, int limit)
{
char *p1, *p2, *endp;
int i = 0;
@@ -229,22 +229,37 @@
do {
add_index_stringl(return_value, i++, p1, p2-p1, 1);
p1 = p2 + delim->value.str.len;
+ if((limit>=0)&&(i>=limit-1))
+ break;
} while ((p2 = php_memnstr(p1, delim->value.str.val, delim->value.str.len, endp)) != NULL);
- if (p1 <= endp) {
+ if ((p1 <= endp)|| ((limit>=0)&&(i>=limit-1))){
add_index_stringl(return_value, i++, p1, endp-p1, 1);
}
}
}
-/* {{{ proto array explode(string separator, string str)
+/* {{{ proto array explode(string separator, string str [, int limit])
Split a string on string separator and return array of components */
PHP_FUNCTION(explode)
{
- zval **str, **delim;
+ zval **str, **delim, **zlimit = NULL;
+ int limit;
- if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &delim, &str) == FAILURE) {
+ switch (ARG_COUNT(ht)) {
+ case 2:
+ if (zend_get_parameters_ex(2, &delim, &str) == FAILURE)
+ WRONG_PARAM_COUNT;
+ limit=-1;
+ break;
+ case 3:
+ if (zend_get_parameters_ex(3, &delim, &str, &zlimit) == FAILURE)
WRONG_PARAM_COUNT;
+ convert_to_long_ex(zlimit);
+ limit = (*zlimit)->value.lval;
+ break;
+ default:
+ WRONG_PARAM_COUNT;
}
convert_to_string_ex(str);
@@ -259,7 +274,11 @@
RETURN_FALSE;
}
- php_explode(*delim, *str, return_value);
+ if((limit==0)||(limit==1)) {
+ add_index_stringl(return_value, 0, (*str)->value.str.val, (*str)->value.str.len, 1);
+ } else {
+ php_explode(*delim, *str, return_value, limit);
+ }
}
/* }}} */
Full Bug description available at: http://bugs.php.net/?id=3251
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Bug Database: "[PHP-DEV] Bug #3922 Updated: == bug"
- Previous message: Manuel Lemos: "Re: [PHP-DEV] Re: [PHP4BETA] PHP 4.0.0 Release packaged"
- Next in thread: Bug Database: "[PHP-DEV] PHP 4.0 Bug #3251 Updated: 3rd arg to explode, (same 3rd arg that split() has)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

