我在变量中有文本:
$string = "foo
bar
cel
[except this title:]
one
naa
";
我需要将它转换为数组但排除“[除了这个标题:]”:
Array
(
[0] => foo
[1] => bar
[2] => cel
[3] => one
[4] => naa
)
我试过这个代码:
$string = "foo
bar
[except this title:]
cel
one
naa";
$array = preg_split("/(\r\n|\n|\r)/", $string);
$i = 1;
foreach($array as $key => $value) {
echo "$i: $value <br>";
$i++;
}
但显示:
1: foo
2: bar
3: [except this title:]
4: cel
5: one
6: naa
我想要这样的显示代码:
1.foo
2.bar
except this title:
3.cel
4.one
5.naa
提前致谢。