gpt4 book ai didi

PHP读取每一行

转载 作者:行者123 更新时间:2023-12-04 15:58:36 25 4
gpt4 key购买 nike

我有一个 <textfield> ($_POST['list'])。

如何将每一行的值获取到数组键?

例子:

<textfield name="list">Burnett River: named by James Burnett, explorer
Campaspe River: named for Campaspe, a mistress of Alexander the Great
Cooper Creek: named for Charles Cooper, Chief Justice of South Australia 1856-1861
Daintree River: named for Richard Daintree, geologist
</textfield>

应转换为:

Array(
[Burnett River: named by James Burnett, explorer]
[Campaspe River: named for Campaspe, a mistress of Alexander the Great]
[Cooper Creek: named for Charles Cooper, Chief Justice of South Australia 1856-1861]
[Daintree River: named for Richard Daintree, geologist]
)

谢谢。

最佳答案

使用explode函数,然后修剪结果数组(以去除任何剩余的 \n\r 或任何意外的空格/制表符):

$lines = explode("\n", $_POST['list']);
$lines = array_map('trim', $lines);

关于PHP读取每一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3619546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com