2

我这里有一些代码:

$testString = "text23hello54stack90overflow34test";
$testArray = preg_split("/[0-9]{2}/Uim", $testString);
echo "<pre>".print_r($testArray)."</pre>";

执行这些命令后,我有一个数组,其中包含:

{text, hello, stack, overflow, test}

我想修改它,所以我得到:

{text, 23hello, 54stack, 90overflow, 34test}

我怎样才能做到这一点?

4

2 回答 2

4

怎么样:

$testString = "text23hello54stack90overflow34test";
$testArray = preg_split("/(?=[0-9]{2})/Uim", $testString);
echo print_r($testArray);

输出:

Array
(
    [0] => text
    [1] => 23hello
    [2] => 54stack
    [3] => 90overflow
    [4] => 34test
)
于 2012-10-08T10:18:47.620 回答
0

使用preg_replace()

$testString = "text23hello54stack90overflow34test";
$testArray = preg_replace("/([0-9]{2})/Uim", ', $1', $testString);

echo $testArray;
// text, 23hello, 54stack, 90overflow, 34test
于 2012-10-08T10:17:26.333 回答