Curtis
Curtis

Reputation: 2704

Removing text and imploding comma

Here I have a text block that I'll be inserting into a database but the format is wrong, currently it's presented to me like this :

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

When I need it to be like this :

24629583,48676466,73003919,03927166,37734358,37132612

Is their anyway to do this quickly other than doing explode() and then preg_replace?

Upvotes: 1

Views: 30

Answers (1)

xpuc7o
xpuc7o

Reputation: 333

You can try this:

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

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

Upvotes: 1

Related Questions