且构网

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

识别并获取PHP字符串中的大写单词

更新时间:2022-05-02 22:29:09

您可以为其使用正则表达式:

You can use a regular expression for it:

preg_match_all('/\b([A-Z]+)\b/', $str, $matches);

要匹配小写字母,请使用以下命令:

To match the lowercase words, use this:

preg_match_all('/\b([a-z]+)\b/', $str, $matches2);

然后,您可以使用implode()之类的功能来构建字符串.

Then you can use functions such as implode() to build the strings.