我有一个如下所示的字符串:
$str = "In order to successfully build your backlinks in a highly competitive industry (or if you're targeting highly competitive keywords), you have to get smart about your strategy. That means using the best back-link building tools available";
现在我想在每三个单词之后拆分字符串。这就是我想要的..
split1 = in order to
split2 = successfully build your
split4 = backlinks in a
依此类推,直到字符串结束。
我已经使用 preg_match_all 完成了它,但它没有给我想要的东西。那么有人可以帮助我使用 split() 或 preg_split 或 explode() 函数拆分字符串。
谢谢
最佳答案
$split = explode(' ', $str); // Split up the whole string
$chunks = array_chunk($split, 3); // Make groups of 3 words
$result = array_map(function($chunk) { return implode(' ', $chunk); }, $chunks); // Put each group back together
$result
是:
Array
(
[0] => In order to
[1] => successfully build your
[2] => backlinks in a
[3] => highly competitive industry
[4] => (or if you're
[5] => targeting highly competitive
[6] => keywords), you have
[7] => to get smart
[8] => about your strategy.
[9] => That means using
[10] => the best back-link
[11] => building tools available
)
关于php - 如何使用爆炸在每三个空间之后拆分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27666117/