300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > php内置函数分析之ucfirst() lcfirst()

php内置函数分析之ucfirst() lcfirst()

时间:2020-01-06 12:12:07

相关推荐

php内置函数分析之ucfirst() lcfirst()

ucfirst($str)

str的首字符(如果首字符是字母)转换为大写字母,并返回这个字符串。

源码位于 ext/standard/string.c

1 /* {{{ php_ucfirst 2 Uppercase the first character of the word in a native string */ 3 static void php_ucfirst(char *str) 4 { 5register char *r; 6r = str; 7*r = toupper((unsigned char) *r); 8 } 9 /* }}} */10 11 /* {{{ proto string ucfirst(string str)12 Makes a string's first character uppercase */13 PHP_FUNCTION(ucfirst)14 {15zend_string *str;16 17ZEND_PARSE_PARAMETERS_START(1, 1)18 Z_PARAM_STR(str)19ZEND_PARSE_PARAMETERS_END();20 21if (!ZSTR_LEN(str)) {22 RETURN_EMPTY_STRING();23}24 25ZVAL_STRINGL(return_value, ZSTR_VAL(str), ZSTR_LEN(str));26php_ucfirst(Z_STRVAL_P(return_value));27 }28 /* }}} */

*r = toupper((unsigned char) *r); 这句调用c函数toupper()将字符数组的第一个元素转为大写。

函数lcfirst()的实现与ucfirst()类似。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。