首页 > 解决方案 > php爆炸的问题,试图分离一个字符串

问题描述

我对这个字符串有问题

string(313) "
12312312312312312
12312312312312312
12312312312312312
12312312312312312
12312312312312312
12312312312312312
12312312312312312
12312312312312312
12312312312312312
12312312312312312"

我想要的结果是=array("12312312312312312","12312312312312312")等...

我想将要放入数组中的条目分开,我用 php 尝试了所有这些方法:

$numbers= explode("\n",$numbers); 

$numbers= explode(" ",$numbers);

$numbers= explode("<br>",$numbers);  

$numbers= str_replace("\n", " ", "<br>", $numbers)

标签: phpexplode

解决方案


您需要explode()使用换行符 ( PHP_EOL):

$numbers= array_filter(explode(PHP_EOL, $numbers)); // PHP_EOL used for new line

print_r($numbers);

输出:- https://3v4l.org/0OH4N

注意:-array_filter()用于从数组中删除空值索引


推荐阅读