删除文本和插入逗号

时间:2016-10-06 15:14:34

标签: php

这里我有一个文本块,我将插入数据库,但格式错误,目前它是这样呈现给我的:

1. 24629583
2. 48676466
3. 73003919
4. 03927166
5. 37734358
6. 37132612

当我需要它时:

24629583,48676466,73003919,03927166,37734358,37132612

除了explode()然后preg_replace之外,他们是否还能快速完成此操作?

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

$string = '1. 24629583
           2. 48676466
           3. 73003919
           4. 03927166
           5. 37734358
           6. 37132612';

$result = preg_replace('/\s+/', ',', preg_replace('/[0-9]+\.\s/', '', $string));
相关问题