ucfirst($str) 将 str 的首字符(如果首字符是字母)转换为大写字母,并返回这个字符串. 源码位于 ext/standard/string.c /* {{{ php_ucfirst Uppercase the first character of the word in a native string */ static void php_ucfirst(char *str) { register char *r; r = str; *r = toupper((unsigned c…
map:会根据提供的函数对指定序列做映射. map(func, *iterables) --> map object Make an iterator that computes the function using arguments from each of the iterables. Stops when the shortest iterable is exhausted. """ 根据提示,map有一个函数名参数还有个动态参数,意思是将可迭代的对象打散然后把…
static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_type) /* {{{ */ { uint idx; Bucket *p; int argc, i; zval *args; int (*diff_data_compare_func)(zval *, zval *) = NULL; zend_bool ok; zval *val, *data; /* Get the argument co…
PHP_FUNCTION(array_combine) { HashTable *values, *keys; uint32_t pos_values = ; zval *entry_keys, *entry_values; int num_keys, num_values; // 创建一个数组,用一个数组的值作为其键名,另一个数组的值作为其值 if (zend_parse_parameters(ZEND_NUM_ARGS(), "hh", &keys, &values…
PHP_FUNCTION(ucwords) { zend_string *str; char *delims = " \t\r\n\f\v"; register char *r, *r_end; size_t delims_len = ; ]; ZEND_PARSE_PARAMETERS_START(, ) Z_PARAM_STR(str) Z_PARAM_OPTIONAL Z_PARAM_STRING(delims, delims_len) ZEND_PARSE_PARAMETERS…
strtoupper(): PHP_FUNCTION(strtoupper) { zend_string *str; ZEND_PARSE_PARAMETERS_START(, ) Z_PARAM_STR(str) ZEND_PARSE_PARAMETERS_END(); RETURN_STR(php_string_toupper(str)); } 主要实现在 php_string_toupper()函数: PHPAPI zend_string *php_string_toupper(zend_…
官方手册中: 类似函数还有两个:ltrim() 和 rtrim().分别处理字符串的左侧.右侧. trim()的具体实现位于:ext/standard/string.c /* {{{ proto string trim(string str [, string character_mask]) Strips whitespace from the beginning and end of a string */ PHP_FUNCTION(trim) { php_do_trim(INTERNAL_…
PHP_FUNCTION(str_pad) { /* Input arguments */ zend_string *input; /* Input string 输入字符串*/ zend_long pad_length; /* Length to pad to 填充到多长.*/ /* Helper variables */ size_t num_pad_chars; /* Number of padding characters (total - input size) 要填充进去的字符个数*…
PHP_FUNCTION(array_fill_keys) { zval *keys, *val, *entry; if (zend_parse_parameters(ZEND_NUM_ARGS(), "az", &keys, &val) == FAILURE) { return; } /* Initialize return array */ array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P…
PHP_FUNCTION(range) { zval *zlow, *zhigh, *zstep = NULL, tmp; , is_step_double = ; double step = 1.0; // 步长默认为1 if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz|z", &zlow, &zhigh, &zstep) == FAILURE) { RETURN_FALSE; } // 步长 if (zstep)…