My raw output of socket_recvfrom is:
ID IP PING IDENTIFIERNUMBER USERNAME
0 127.0.0.1:1234 0 ID123456789 Moritz
1 127.0.0.1:1234 46 ID123456789 August Jones
2 127.0.0.1:1234 46 ID123456789 Miller
It is a single string that contains all of this informations in once and just contains whitespaces between the informations. All keys can be longer or shorter.
My problem:
When I preg_split("/\s+/")
it, then I get a good array with useable data, but when the username contains spaces it creates a second index for this. Not good, all data that comes after this just get destroyed.
I sort the array like this: ID, USERNAME, PING, IDENTIFIERNUMBER, IP
Example by the sorting output with username with one space in it:
ID: 0, USERNAME: Moritz, PING: 0, IDENTIFIERNUMBER: ID123456789, IP: 127.0.0.1:1234
ID: 1, USERNAME: August, PING: Jones, IDENTIFIERNUMBER: 46, IP: ID123456789
ID: 127.0.0.1:1234, USERNAME: 2, PING: Miller, IDENTIFIERNUMBER: 46, IP: ID123456789
How do I get the information correctly out of the string?
Just forgot to say:
The string begins with: ---------------------------------
in a not countable order. So it can be like 10 characters or 12.
The string ends with:
(8 users in total)
The regex methode looks good. I only need to filter out the other characters.
--------------------------------- 0 127.0.0.1:1234 0 ID123456789(OK) Moritz 1 127.0.0.1:1234 46 ID123456789(OK) August Jones 2 127.0.0.1:1234 46 ID123456789(OK) Miller (7 users in total)
Last problem: https://www.regex101.com/r/wP8cW1/1