【发布时间】:2016-03-22 22:42:04
【问题描述】:
我有一批这样的字符串:
tHe iPad hAS gONE ouT of STOCK
PoWER uP YOur iPhone
wHAT moDEL is YOUR aPPLE iPHOne
我想将每个单词的第一个字符大写,其余字符小写——iPhone 或 iPad 的任何引用除外。如:
通过使用:
ucwords(strtolower($string));
这可以做大部分需要的事情,但显然也可以在iPad和iPhone上做:
The Ipad Has Gone Out Of Stock
Power Up Your Iphone
What Model Is Your Apple Iphone
我怎样才能做到以下几点:
The iPad Has Gone Out Of Stock
Power Up Your iPhone
What Model Is Your Apple iPhone
【问题讨论】:
-
然后,您必须检查几个单词的条件。如果没有找到这些词,则应用条件。
-
可以做一个正则表达式; regex101.com/r/bH2yY6/1
-
echo preg_replace('@Ip@','iP', ucwords( strtolower( $string ) ) );?
标签: php string lowercase capitalize