Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

havvtom's avatar

Reading and making an array from a file

I have a text file and I want to make an array form the line below.

8295       MRS B ADAMS                             13469.58            0.00        13479.58         1456.43        3452.16

the desired output is 
[8295, MRS B ADAMS, 13469.58, 0.00, 1456.43, 3452.16]

the problem is the spaces are not regular and I want the name MRS N ABRAMS to be one word. I have tried regex but it also splits the name MRS N ABRAMS into three elements.

0 likes
2 replies
RayC's avatar

Looks like the file has the fields separated by a tab, If you specify the proper separator the MRS B ADAMS will be one element instead of three.

Sinnbeck's avatar

Aren't those tabs? Is it a csv file? Can you show your code?

Please or to participate in this conversation.