static void php_strtr_array(zval *return_value, char *str, int slen, HashTable *hash)
{
zval **entry;
char *string_key;
uint string_key_len;
zval **trans;
zval ctmp;
ulong num_key;
int minlen = 128*1024;
int maxlen = 0, pos, len, found;
char *key ;
HashPosition hpos;
smart_str result = {0};
HashTable tmp_hash;
//Copy the replacement array from hash to tmp_hash, and record the maximum and minimum length of the subscript string
zend_hash_init(&tmp_hash, 0, NULL, NULL, 0);
zend_hash_internal_pointer_reset_ex(hash, &hpos);
while (zend_hash_get_current_data_ex(hash, (void **)&entry, &hpos) == SUCCESS) {
switch (zend_hash_get_current_key_ex(hash, &string_key, &string_key_len, &num_key, 0, &hpos)) {
len = string_key_len-1;
through );
zend_hash_add(&tmp_hash, string_key, string_key_len, entry, sizeof(zval*), NULL); maxlen = len ;
minlen = len;
break; 🎜> case HASH_KEY_IS_LONG:
Z_LVAL(ctmp) = num_key;
len = Z_STRLEN(ctmp);
zend_hash_add(&tmp_hash, Z_STRVAL(ctmp), len+1, entry, sizeof(zval*), NULL);
zval_dtor(&ctmp);
if (len > maxlen }
if (len & lt; minlen) {
minlen = len;
}
Break;
}
Zend_hash_Move_Forward_ex (have, & hpos); emalloc(maxlen+1);
pos = 0;
//Loop matching starting from the first character of the string, pos records the current search position
while (pos < slen) {
}
found = 0; ','ab'=>'f'), it will replace ab with f first instead of replacing a with e first.
Quite high
if (zend_hash_find(&tmp_hash, key, len+1, (void**)&trans) == SUCCESS) {
int tlen;
zval tmp;
if ( Z_TYPE_PP(trans) != IS_STRING) {
(andtmp); 🎜> tlen = Z_STRLEN (tmp);
tlen = Z_STRLEN_PP(trans);
If (Z_TYPE_PP(trans ) != IS_STRING) {
smart_str_appendc(&result, str[pos++ ]);
}
}
efree(key);
zend_hash_destroy(&tmp_hash);
smart_str_0(&result);
RETVAL_STRINGL(result.c, result.len, 0) ;
}
http://www.bkjia.com/PHPjc/327900.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/327900.html
TechArticle
Recently, we often need to match and replace strings. In the past, we usually used str_replace or preg_replace. It is said that strtr is very efficient. , so compare it: Copy the code code as...