0

我有一个长度约为 50k 的字符串。字符串示例

hdjhjdhjdhdhjdhjhdldkklkdklkllkldkldldkl kldkldkl OR hdjhjdhjdhdhjdhjhdldkklkdklkllkldkldldkl kldkldkl hdjhjdhjdhdhjdhjhdldkklkdklkllkldkldldkl kldkldkl OR hdjhjdhjdhdhjdhjhdldkklkdklkllkldkldldkl kldkldkl hdjhjdhjdhdhjdhjhdldkklkdklkllkldkldldkl kldkldkl hdjhjdhjdhdhjdhjhdldkklkdklkllkldkldldkl kldkldkl hdjhjdhjdhdhjdhjhdldkklkdklkllkldkldldkl kldkldkl hdjhjdhjdhdhjdhjhdldkklkdklkllkldkldldkl kldkldkl OR kdjkdjkdjkj OR djdldkkldkkkldklddklkldkl OR jdkdkjdjkjkdjkdjkdjkjkjkjkdkjkdjkjkdjkjk OR hdjhjdhjdhdhjdhjhdldkklkdklkllkldkldldkl kldkldkl hdjhjdhjdhdhjdhjhdldkklkdklkllkldkldldkl kldkldkl hdjhjdhjdhdhjdhjhdldkklkdklkllkldkldldkl kldkldkl hdjhjdhjdhdhjdhjhdldkklkdklkllkldkldldkl kldkldkl OR llldlkdl dkld ldk

现在如果我使用explode('OR', $str);,它会给我长度为 500 或超过 501 的数组。

但我只需要 10 个数组。最后一个数组可能很长。有没有人有想法。如何做到这一点..我需要OR字符串本身的单词。 我也有 20k OR 在一个字符串

谢谢

4

3 回答 3

3
str_split($str, strlen($str) / 10);
于 2013-09-25T10:48:36.830 回答
2

这应该工作

explode('OR', $string, 10);

第三个参数是数组中数组项的最大数量,最后一个将保存剩余的字符串。

如果您确实需要OR字符串内部,则应改用@Alix Axel 的答案。

于 2013-09-25T10:48:39.253 回答
0

给你(演示):

preg_split('~(?<!\b20k\b) OR\b~', $str, 10);

我建议下一次,你清楚地陈述你的整个、完整的问题。

于 2013-09-25T12:27:27.793 回答