cvs: php4 /ext/standard string.c /ext/standard/tests/strings substr_replace.phpt

From: Date: Fri, 02 May 2003 10:02:40 +0000
Subject: cvs: php4 /ext/standard string.c /ext/standard/tests/strings substr_replace.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-20653@lists.php.net to get a copy of this message
andrey Fri May 2 06:02:40 2003 EDT Added files: /php4/ext/standard/tests/strings substr_replace.phpt Modified files: /php4/ext/standard string.c Log: Extending substr_replace(). Every parameter can be mixed (string/array) also the return type. #see the test file if you need more info.

Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.376 php4/ext/standard/string.c:1.377 --- php4/ext/standard/string.c:1.376 Tue Apr 29 09:35:48 2003 +++ php4/ext/standard/string.c Fri May 2 06:02:40 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.376 2003/04/29 13:35:48 wez Exp $ */ +/* $Id: string.c,v 1.377 2003/05/02 10:02:40 andrey Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -1833,13 +1833,14 @@ } /* }}} */ -/* {{{ proto string substr_replace(string str, string repl, int start [, int length]) + +/* {{{ proto mixed substr_replace(mixed str, mixed repl, mixed start [, mixed length]) Replaces part of a string with another string */ PHP_FUNCTION(substr_replace) { zval **str; zval **from; - zval **len; + zval **len = NULL; zval **repl; char *result; int result_len; @@ -1847,60 +1848,229 @@ int f; int argc = ZEND_NUM_ARGS(); + HashPosition pos_str, pos_from, pos_repl, pos_len; + zval **tmp_str = NULL, **tmp_from = NULL, **tmp_repl = NULL, **tmp_len= NULL; + + if (argc < 3 || argc > 4 || zend_get_parameters_ex(argc, &str, &repl, &from, &len) == FAILURE) { WRONG_PARAM_COUNT; } - - convert_to_string_ex(str); - convert_to_string_ex(repl); - convert_to_long_ex(from); + if (Z_TYPE_PP(str) != IS_ARRAY) { + convert_to_string_ex(str); + } + if (Z_TYPE_PP(repl) != IS_ARRAY) { + convert_to_string_ex(repl); + } + if (Z_TYPE_PP(from) != IS_ARRAY) { + convert_to_long_ex(from); + } + if (argc > 3) { - convert_to_long_ex(len); - l = Z_LVAL_PP(len); + if (Z_TYPE_PP(len) != IS_ARRAY) { + convert_to_long_ex(len); + l = Z_LVAL_PP(len); + } } else { - l = Z_STRLEN_PP(str); + if (Z_TYPE_PP(str) != IS_ARRAY) { + l = Z_STRLEN_PP(str); + } } - - f = Z_LVAL_PP(from); - /* if "from" position is negative, count start position from the end - * of the string - */ - if (f < 0) { - f = Z_STRLEN_PP(str) + f; - if (f < 0) { - f = 0; + if (Z_TYPE_PP(str) == IS_STRING) { + if ( + (argc == 3 && Z_TYPE_PP(from) == IS_ARRAY) + || + (argc == 4 && Z_TYPE_PP(from) != Z_TYPE_PP(len)) + ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "'from' and 'len' should be of same type - numerical or array "); + RETURN_STRINGL(Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1); + } + if (argc == 4 && Z_TYPE_PP(from) == IS_ARRAY) { + if (zend_hash_num_elements(Z_ARRVAL_PP(from)) != zend_hash_num_elements(Z_ARRVAL_PP(len))) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "'from' and 'len' should have the same number of elements"); + RETURN_STRINGL(Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1); + } } - } else if (f > Z_STRLEN_PP(str)) { - f = Z_STRLEN_PP(str); } + + if (Z_TYPE_PP(str) != IS_ARRAY) { + if (Z_TYPE_PP(from) != IS_ARRAY) { + int repl_len = 0; - /* if "length" position is negative, set it to the length - * needed to stop that many chars from the end of the string - */ - if (l < 0) { - l = (Z_STRLEN_PP(str) - f) + l; - if (l < 0) { - l = 0; + f = Z_LVAL_PP(from); + + /* if "from" position is negative, count start position from the end + * of the string + */ + if (f < 0) { + f = Z_STRLEN_PP(str) + f; + if (f < 0) { + f = 0; + } + } else if (f > Z_STRLEN_PP(str)) { + f = Z_STRLEN_PP(str); + } + /* if "length" position is negative, set it to the length + * needed to stop that many chars from the end of the string + */ + if (l < 0) { + l = (Z_STRLEN_PP(str) - f) + l; + if (l < 0) { + l = 0; + } + } + + if ((f + l) > Z_STRLEN_PP(str)) { + l = Z_STRLEN_PP(str) - f; + } + if (Z_TYPE_PP(repl) == IS_ARRAY) { + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(repl), &pos_repl); + if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(repl), (void **) &tmp_repl, &pos_repl)) { + convert_to_string_ex(tmp_repl); + repl_len = Z_STRLEN_PP(tmp_repl); + } + result_len = Z_STRLEN_PP(str) - l + repl_len; + result = ecalloc(result_len + 1, sizeof(char *)); + + memcpy(result, Z_STRVAL_PP(str), f); + if (repl_len) { + memcpy(&result[f], Z_STRVAL_PP(tmp_repl), repl_len); + } + } else { + repl_len = Z_STRLEN_PP(repl); + result_len = Z_STRLEN_PP(str) - l + repl_len; + result = ecalloc(result_len + 1, sizeof(char *)); + + memcpy(result, Z_STRVAL_PP(str), f); + memcpy(&result[f], Z_STRVAL_PP(repl), repl_len); + } + memcpy(&result[f + repl_len], Z_STRVAL_PP(str) + f + l, Z_STRLEN_PP(str) - f - l); + RETURN_STRINGL(result, result_len, 0); + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Functionality of 'from' and 'len' as arrays is not implemented."); + RETURN_STRINGL(Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1); } - } + } else { /* str is array of strings */ + + array_init(return_value); - if ((f + l) > Z_STRLEN_PP(str)) { - l = Z_STRLEN_PP(str) - f; - } + if (Z_TYPE_PP(from) == IS_ARRAY) { + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(from), &pos_from); + } - result_len = Z_STRLEN_PP(str) - l + Z_STRLEN_PP(repl); - result = ecalloc(result_len + 1, sizeof(char *)); + if (argc > 3 && Z_TYPE_PP(len) == IS_ARRAY) { + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(len), &pos_len); + } + + if (Z_TYPE_PP(repl) == IS_ARRAY) { + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(repl), &pos_repl); + } + + + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(str), &pos_str); + while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(str), (void **) &tmp_str, &pos_str) == SUCCESS) { + convert_to_string_ex(tmp_str); + + if (Z_TYPE_PP(from) == IS_ARRAY) { + if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(from), (void **) &tmp_from, &pos_from)) { + convert_to_long_ex(tmp_from); + + f = Z_LVAL_PP(tmp_from); + if (f < 0) { + f = Z_STRLEN_PP(tmp_str) + f; + if (f < 0) { + f = 0; + } + } else if (f > Z_STRLEN_PP(tmp_str)) { + f = Z_STRLEN_PP(tmp_str); + } + zend_hash_move_forward_ex(Z_ARRVAL_PP(from), &pos_from); + } else { + f = 0; + } + } else { + f = Z_LVAL_PP(from); + if (f < 0) { + f = Z_STRLEN_PP(tmp_str) + f; + if (f < 0) { + f = 0; + } + } else if (f > Z_STRLEN_PP(tmp_str)) { + f = Z_STRLEN_PP(tmp_str); + } + } + + + if (argc > 3 && Z_TYPE_PP(len) == IS_ARRAY) { + if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(len), (void **) &tmp_len, &pos_len)) { + convert_to_long_ex(tmp_len); + + l = Z_LVAL_PP(tmp_len); + zend_hash_move_forward_ex(Z_ARRVAL_PP(len), &pos_len); + } else { + l = Z_STRLEN_PP(tmp_str); + } + } else if (argc > 3) { + l = Z_LVAL_PP(len); + } else { + l = Z_STRLEN_PP(tmp_str); + } + + if (l < 0) { + l = (Z_STRLEN_PP(tmp_str) - f) + l; + if (l < 0) { + l = 0; + } + } + + + if ((f + l) > Z_STRLEN_PP(tmp_str)) { + l = Z_STRLEN_PP(tmp_str) - f; + } + + result_len = Z_STRLEN_PP(tmp_str) - l; + + if (Z_TYPE_PP(repl) == IS_ARRAY) { + if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(repl), (void **) &tmp_repl, &pos_repl)) { + convert_to_string_ex(tmp_repl); + result_len += Z_STRLEN_PP(tmp_repl); + zend_hash_move_forward_ex(Z_ARRVAL_PP(repl), &pos_repl); + result = ecalloc(result_len + 1, sizeof(char *)); + + memcpy(result, Z_STRVAL_PP(tmp_str), f); + memcpy(&result[f], Z_STRVAL_PP(tmp_repl), Z_STRLEN_PP(tmp_repl)); + memcpy(&result[f + Z_STRLEN_PP(tmp_repl)], Z_STRVAL_PP(tmp_str) + f + l, Z_STRLEN_PP(tmp_str) - f - l); + } else { + result = ecalloc(result_len + 1, sizeof(char *)); + + memcpy(result, Z_STRVAL_PP(tmp_str), f); + memcpy(&result[f], Z_STRVAL_PP(tmp_str) + f + l, Z_STRLEN_PP(tmp_str) - f - l); + } + + } else { + result_len += Z_STRLEN_PP(repl); + + result = ecalloc(result_len + 1, sizeof(char *)); - memcpy(result, Z_STRVAL_PP(str), f); - memcpy(&result[f], Z_STRVAL_PP(repl), Z_STRLEN_PP(repl)); - memcpy(&result[f + Z_STRLEN_PP(repl)], Z_STRVAL_PP(str) + f + l, Z_STRLEN_PP(str) - f - l); - RETURN_STRINGL(result, result_len, 0); + memcpy(result, Z_STRVAL_PP(tmp_str), f); + memcpy(&result[f], Z_STRVAL_PP(repl), Z_STRLEN_PP(repl)); + memcpy(&result[f + Z_STRLEN_PP(repl)], Z_STRVAL_PP(tmp_str) + f + l, Z_STRLEN_PP(tmp_str) - f - l); + } + + + add_next_index_stringl(return_value, result, result_len, 0); + + zend_hash_move_forward_ex(Z_ARRVAL_PP(str), &pos_str); + } /*while*/ + } /* if */ } /* }}} */ + + + /* {{{ proto string quotemeta(string str) Quotes meta characters */ Index: php4/ext/standard/tests/strings/substr_replace.phpt +++ php4/ext/standard/tests/strings/substr_replace.phpt --TEST-- substr_replace() function --POST-- --GET-- --FILE-- <?php $str = "try this"; $repl = "bala "; $start = 2; echo "\n"; echo "substr_replace('$str', '$repl', $start)\n"; var_dump(substr_replace($str, $repl, $start)); echo "\n"; $len = 3; echo "substr_replace('$str', '$repl', $start, $len)\n"; var_dump(substr_replace($str, $repl, $start, $len)); echo "\n"; $len = 0; echo "substr_replace('$str', '$repl', $start, $len)\n"; var_dump(substr_replace($str, $repl, $start, $len)); echo "\n"; $len = -2; echo "substr_replace('$str', '$repl', $start, $len)\n"; var_dump(substr_replace($str, $repl, $start, $len)); echo "\n"; echo "\n"; echo "\n"; $str = "try this"; $repl = array("bala "); $start = 4; $len = 3; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).", ".var_export($start,1)."")."\n"; var_dump(substr_replace($str, $repl, $start))."\n"; echo "\n"; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).", ".var_export($start,1)."")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $str = array("ala portokala"); $repl = array("bala "); $start = array(4); $len = array(3); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).", ".var_export($start,1)."")."\n"; var_dump(substr_replace($str, $repl, $start))."\n"; echo "\n"; $len = array(3); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).", ".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; $len = array(0); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).", ".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; $len = array(-2); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).", ".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; echo "\n"; $str = array("ala portokala"); $repl = "bala "; $start = 4; $len = 3; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).")")."\n"; var_dump(substr_replace($str, $repl, $start))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = 4; $len = 3; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = 4; $len = 3; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = 4; $len = 0; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = 4; $len = 0; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = 4; $len = -2; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = 4; $len = -2; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $str = array("ala portokala"); $repl = "bala "; $start = array(4); $len = 3; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).")")."\n"; var_dump(substr_replace($str, $repl, $start))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = array(4); $len = 3; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = array(4); $len = 3; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = array(4); $len = 0; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = array(4); $len = 0; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = array(4); $len = -2; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = array(4); $len = -2; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $str = array("ala portokala"); $repl = "bala "; $start = array(4,2); $len = 3; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).")")."\n"; var_dump(substr_replace($str, $repl, $start))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = array(4,2); $len = 3; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = array(4,2); $len = 3; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = array(4,2); $len = 0; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = array(4,2); $len = 0; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = array(4,2); $len = -2; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = array(4,2); $len = -2; echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $str = array("ala portokala"); $repl = "bala "; $start = array(4,2); $len = array(3); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).")")."\n"; var_dump(substr_replace($str, $repl, $start))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = array(4,2); $len = array(3); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = array(4,2); $len = array(3); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = array(4,2); $len = array(0); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = array(4,2); $len = array(0); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = array(4,2); $len = array(-2); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = array(4,2); $len = array(-2); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $str = array("ala portokala"); $repl = "bala "; $start = array(4,2); $len = array(3,2); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).")")."\n"; var_dump(substr_replace($str, $repl, $start))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = array(4,2); $len = array(3,2); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = array(4,2); $len = array(3,2); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = array(4,2); $len = array(0,0); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = array(4,2); $len = array(0,0); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = array("bala "); $start = array(4,2); $len = array(-2,-3); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; echo "\n"; $str = array("ala portokala", "try this"); $repl = "bala "; $start = array(4,2); $len = array(-2,-3); echo str_replace("\n","","substr_replace(".var_export($str,1).", ".var_export($repl,1).",".var_export($start,1).", ".var_export($len,1).")")."\n"; var_dump(substr_replace($str, $repl, $start, $len))."\n"; echo "\n"; ?> --EXPECT-- substr_replace('try this', 'bala ', 2) string(7) "trbala " substr_replace('try this', 'bala ', 2, 3) string(10) "trbala his" substr_replace('try this', 'bala ', 2, 0) string(13) "trbala y this" substr_replace('try this', 'bala ', 2, -2) string(9) "trbala is" substr_replace('try this', array ( 0 => 'bala ',), 4 string(9) "try bala " substr_replace('try this', array ( 0 => 'bala ',), 4 string(10) "try bala s" substr_replace(array ( 0 => 'ala portokala',), array ( 0 => 'bala ',), array ( 0 => 4,) array(1) { [0]=> string(9) "ala bala " } substr_replace(array ( 0 => 'ala portokala',), array ( 0 => 'bala ',), array ( 0 => 4,), array ( 0 => 3,)) array(1) { [0]=> string(15) "ala bala tokala" } substr_replace(array ( 0 => 'ala portokala',), array ( 0 => 'bala ',), array ( 0 => 4,), array ( 0 => 0,)) array(1) { [0]=> string(18) "ala bala portokala" } substr_replace(array ( 0 => 'ala portokala',), array ( 0 => 'bala ',), array ( 0 => 4,), array ( 0 => -2,)) array(1) { [0]=> string(11) "ala bala la" } substr_replace(array ( 0 => 'ala portokala',), 'bala ',4) array(1) { [0]=> string(9) "ala bala " } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),4, 3) array(2) { [0]=> string(15) "ala bala tokala" [1]=> string(5) "try s" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',4, 3) array(2) { [0]=> string(15) "ala bala tokala" [1]=> string(10) "try bala s" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),4, 0) array(2) { [0]=> string(18) "ala bala portokala" [1]=> string(8) "try this" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',4, 0) array(2) { [0]=> string(18) "ala bala portokala" [1]=> string(13) "try bala this" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),4, -2) array(2) { [0]=> string(11) "ala bala la" [1]=> string(6) "try is" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',4, -2) array(2) { [0]=> string(11) "ala bala la" [1]=> string(11) "try bala is" } substr_replace(array ( 0 => 'ala portokala',), 'bala ',array ( 0 => 4,)) array(1) { [0]=> string(9) "ala bala " } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),array ( 0 => 4,), 3) array(2) { [0]=> string(15) "ala bala tokala" [1]=> string(5) " this" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',array ( 0 => 4,), 3) array(2) { [0]=> string(15) "ala bala tokala" [1]=> string(10) "bala this" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),array ( 0 => 4,), 0) array(2) { [0]=> string(18) "ala bala portokala" [1]=> string(8) "try this" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',array ( 0 => 4,), 0) array(2) { [0]=> string(18) "ala bala portokala" [1]=> string(13) "bala try this" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),array ( 0 => 4,), -2) array(2) { [0]=> string(11) "ala bala la" [1]=> string(2) "is" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',array ( 0 => 4,), -2) array(2) { [0]=> string(11) "ala bala la" [1]=> string(7) "bala is" } substr_replace(array ( 0 => 'ala portokala',), 'bala ',array ( 0 => 4, 1 => 2,)) array(1) { [0]=> string(9) "ala bala " } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),array ( 0 => 4, 1 => 2,), 3) array(2) { [0]=> string(15) "ala bala tokala" [1]=> string(5) "trhis" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',array ( 0 => 4, 1 => 2,), 3) array(2) { [0]=> string(15) "ala bala tokala" [1]=> string(10) "trbala his" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),array ( 0 => 4, 1 => 2,), 0) array(2) { [0]=> string(18) "ala bala portokala" [1]=> string(8) "try this" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',array ( 0 => 4, 1 => 2,), 0) array(2) { [0]=> string(18) "ala bala portokala" [1]=> string(13) "trbala y this" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),array ( 0 => 4, 1 => 2,), -2) array(2) { [0]=> string(11) "ala bala la" [1]=> string(4) "tris" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',array ( 0 => 4, 1 => 2,), -2) array(2) { [0]=> string(11) "ala bala la" [1]=> string(9) "trbala is" } substr_replace(array ( 0 => 'ala portokala',), 'bala ',array ( 0 => 4, 1 => 2,)) array(1) { [0]=> string(9) "ala bala " } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),array ( 0 => 4, 1 => 2,), array ( 0 => 3,)) array(2) { [0]=> string(15) "ala bala tokala" [1]=> string(2) "tr" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',array ( 0 => 4, 1 => 2,), array ( 0 => 3,)) array(2) { [0]=> string(15) "ala bala tokala" [1]=> string(7) "trbala " } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),array ( 0 => 4, 1 => 2,), array ( 0 => 0,)) array(2) { [0]=> string(18) "ala bala portokala" [1]=> string(2) "tr" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',array ( 0 => 4, 1 => 2,), array ( 0 => 0,)) array(2) { [0]=> string(18) "ala bala portokala" [1]=> string(7) "trbala " } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),array ( 0 => 4, 1 => 2,), array ( 0 => -2,)) array(2) { [0]=> string(11) "ala bala la" [1]=> string(2) "tr" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',array ( 0 => 4, 1 => 2,), array ( 0 => -2,)) array(2) { [0]=> string(11) "ala bala la" [1]=> string(7) "trbala " } substr_replace(array ( 0 => 'ala portokala',), 'bala ',array ( 0 => 4, 1 => 2,)) array(1) { [0]=> string(9) "ala bala " } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),array ( 0 => 4, 1 => 2,), array ( 0 => 3, 1 => 2,)) array(2) { [0]=> string(15) "ala bala tokala" [1]=> string(6) "trthis" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',array ( 0 => 4, 1 => 2,), array ( 0 => 3, 1 => 2,)) array(2) { [0]=> string(15) "ala bala tokala" [1]=> string(11) "trbala this" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),array ( 0 => 4, 1 => 2,), array ( 0 => 0, 1 => 0,)) array(2) { [0]=> string(18) "ala bala portokala" [1]=> string(8) "try this" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',array ( 0 => 4, 1 => 2,), array ( 0 => 0, 1 => 0,)) array(2) { [0]=> string(18) "ala bala portokala" [1]=> string(13) "trbala y this" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), array ( 0 => 'bala ',),array ( 0 => 4, 1 => 2,), array ( 0 => -2, 1 => -3,)) array(2) { [0]=> string(11) "ala bala la" [1]=> string(5) "trhis" } substr_replace(array ( 0 => 'ala portokala', 1 => 'try this',), 'bala ',array ( 0 => 4, 1 => 2,), array ( 0 => -2, 1 => -3,)) array(2) { [0]=> string(11) "ala bala la" [1]=> string(10) "trbala his" }
« previous php.cvs (#20653) next »