且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP-每个单词的首字母大写期望某些单词

更新时间:2023-01-17 13:54:35

为此 str_replace 。如果对前两个参数使用数组,则可以定义一组单词和替换:

You can use str_replace for this. If you use arrays for the first two arguments, you can define a set of words and replacements:

echo str_replace(['Ipad', 'Iphone'], ['iPad', 'iPhone'], ucwords(strtolower($string)));

来自文档:


如果搜索和替换是数组,则str_replace()从每个数组中获取一个值,并使用它们对主题进行搜索和替换。

If search and replace are arrays, then str_replace() takes a value from each array and uses them to search and replace on subject.