php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #39962
Patch substr_insert.patch revision 2011-08-23 15:37 UTC by datibbaw@php.net
revision 2011-08-23 14:08 UTC by datibbaw@php.net
revision 2011-08-23 14:05 UTC by datibbaw@php.net

Patch substr_insert.patch for *General Issues Bug #39962

Patch version 2011-08-23 14:08 UTC

Return to Bug #39962 | Download this patch
This patch is obsolete

Obsoleted by patches:

This patch renders other patches obsolete

Obsolete patches:

Patch Revisions:

Developer: datibbaw@php.net

Index: string.c
===================================================================
--- string.c	(revision 315071)
+++ string.c	(working copy)
@@ -2543,6 +2543,43 @@
 }
 /* }}} */
 
+/* {{{ proto string substr_insert(string str, string insert [, int start])
+   Inserts a string into another string */ 
+PHP_FUNCTION(substr_insert)
+{
+	char *str, *insert, *result;
+	int str_len, insert_len, result_len;
+	long start = 0;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &str, &str_len, &insert, &insert_len, &start) == FAILURE) {
+		return;
+	}
+
+	if (start < 0) {
+		start = str_len + start;
+		if (start < 0) {
+			start = 0;
+		} 
+	} else if (start > str_len) {
+		start = str_len;
+	}
+
+	result_len = str_len + insert_len;
+	result = emalloc(result_len + 1); 
+
+	if (start) {
+		memcpy(result, str, start);
+	}
+	memcpy((result + start), insert, insert_len);
+	if (from != str_len) {
+		memcpy((result + start + insert_len), (str + start), str_len - start); 
+	}
+	result[result_len] = '\0';
+
+	RETURN_STRINGL(result, result_len, 0);
+}
+/* }}} */
+
 /* {{{ proto string quotemeta(string str)
    Quotes meta characters */
 PHP_FUNCTION(quotemeta)
Index: basic_functions.c
===================================================================
--- basic_functions.c	(revision 315071)
+++ basic_functions.c	(working copy)
@@ -2296,6 +2296,12 @@
 	ZEND_ARG_INFO(0, length)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(arginfo_substr_insert, 0, 0, 3)
+	ZEND_ARG_INFO(0, str)
+	ZEND_ARG_INFO(0, insert)
+	ZEND_ARG_INFO(0, start)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO(arginfo_quotemeta, 0)
 	ZEND_ARG_INFO(0, str)
 ZEND_END_ARG_INFO()
@@ -2773,6 +2779,8 @@
 
 	PHP_FE(substr,															arginfo_substr)
 	PHP_FE(substr_replace,													arginfo_substr_replace)
+	PHP_FE(substr_insert,
+							arginfo_substr_insert)
 	PHP_FE(quotemeta,														arginfo_quotemeta)
 	PHP_FE(ucfirst,															arginfo_ucfirst)
 	PHP_FE(lcfirst,															arginfo_lcfirst)
Index: php_string.h
===================================================================
--- php_string.h	(revision 315071)
+++ php_string.h	(working copy)
@@ -83,6 +83,7 @@
 PHP_FUNCTION(strip_tags);
 PHP_FUNCTION(str_repeat);
 PHP_FUNCTION(substr_replace);
+PHP_FUNCTION(substr_insert);
 PHP_FUNCTION(strnatcmp);
 PHP_FUNCTION(strnatcasecmp);
 PHP_FUNCTION(substr_count);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 07:01:29 2024 UTC