PHP编写函数change($str)实现字符串转换功能,例如“str_replace”转换成"S?

如题所述

    如果是小写转大写即“str_replace”转换成“STR_REPLACE”?

php内置了函数strtoupper(),直接strtoupper("str_replace")即可,如果你要写成change函数,那么就是:

function change($str){

    return strtoupper($str);

}

2.如果就是从“str_replace”转换成"S",可以使用substr等字符串操作函数,比如:

function change($str){

    return substr( strtoupper($str), 0, 1 );

}

温馨提示:答案为网友推荐,仅供参考