php explode 的问题,试图分隔字符串
Problem with php explode, trying to separate a string
我对这个字符串有疑问
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)
您需要 explode()
换行 (PHP_EOL
):
$numbers= array_filter(explode(PHP_EOL, $numbers)); // PHP_EOL used for new line
print_r($numbers);
注意:- array_filter()
用于从数组中删除空值索引
首先用简单的 space 替换任何换行元素,例如喜欢
$numbers = trim(preg_replace('/\s+/', ' ', $numbers));
你可以简单地使用你已经尝试过的爆炸:
$numbers = explode(" ",$numbers);
您可以按此顺序初始化字符串。
这可能对你有帮助
$str ="12312312312312312 12312312312312312 12312312312312312 12312312312312312 12312312312312312 12312312312312312 12312312312312312";
var_dump(explode(" ",$str));
我对这个字符串有疑问
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)
您需要 explode()
换行 (PHP_EOL
):
$numbers= array_filter(explode(PHP_EOL, $numbers)); // PHP_EOL used for new line
print_r($numbers);
注意:- array_filter()
用于从数组中删除空值索引
首先用简单的 space 替换任何换行元素,例如喜欢
$numbers = trim(preg_replace('/\s+/', ' ', $numbers));
你可以简单地使用你已经尝试过的爆炸:
$numbers = explode(" ",$numbers);
您可以按此顺序初始化字符串。 这可能对你有帮助
$str ="12312312312312312 12312312312312312 12312312312312312 12312312312312312 12312312312312312 12312312312312312 12312312312312312";
var_dump(explode(" ",$str));