按大写字母拆分单词

10
我想在PHP中按大写字母拆分单词。
例如:
$string = "facebookPageUrl";

我想要它像这样:

$array = array("facebook", "Page", "Url");

我该怎么做?我想要最短且最有效的方法。

2个回答

17

@JohnSmith 你在哪里找到的?又是在 Stack Overflow 上的问题吗? - Gumbo
在php.net上,我找到了类似这样的东西。 - John Smith

4
$string = "facebookPageUrl";

preg_match_all('((?:^|[A-Z])[^A-Z]*)', $string, $matches);
var_dump($matches);

http://ideone.com/wL9jM


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接