如何爆炸多行字符串?
问题描述:
我有一个在每一行上具有不同值的字符串:
I have a string that has different values on each line:
$matches="value1
value2
value3
value4
value5
";
我想将整个字符串分解为一个由各个值组成的数组.我知道如何爆炸以空格分隔的字符串,例如explode(' ', $matches)
.但是如何在这种类型的字符串上使用爆炸功能?
I want to explode the whole string in to an array consisting of the values separeted. I know how to explode a space separated string, like explode(' ', $matches)
. But how do i use the explode function on this type of string?
我尝试过:
$matches=explode('\n',$matches);
print_r($matches);
但结果是:
Array
(
[0] => hello
hello
hello
hello
hello
hello
hello
)