php - 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)
解决方案
您需要explode()
使用换行符 ( PHP_EOL
):
$numbers= array_filter(explode(PHP_EOL, $numbers)); // PHP_EOL used for new line
print_r($numbers);
注意:-array_filter()
用于从数组中删除空值索引
推荐阅读
- google-apps-script - 如何将行移动到命名范围的最后一行(onEdit)
- java - # 在 XML 命名空间中似乎导致 java API 中的异常——为什么?
- optimization - 如何在 CPLEX ILOG 上创建的模型中实现本地搜索算法?
- gmp - 为什么我不能将这个科学记数法读入 GMP mpf_t?
- ios - iOS Swift 代码 - 当我有断点时才工作
- node.js - 如何通过填充字段在猫鼬中查找文档?
- javascript - 用于通过 require 导入的 JSON 文件的 Visual Studio Code Intellisense
- node.js - Node 和 Express – 有条件地显示页面
- android - 为什么 RecyclerView 在没有 notifyDataSetChanged() 的情况下更新?
- android - Android ProGuard:保持内部注释接口