I have a text document that is opened and read by php that looks like this
ABC: 123
DEF: 456
GHI: 789
So basically it is one piece of text ended with a colon, followed by another piece of text. To separate the lines there is a line break (i.e. ” \n “)
Is it possible to have this go into an array separated by the colon and the line break? So that when I print the value it should look like this:
” ABC:123,DEF:456,GHI:789 “
First thing you need to do is split those lines up.
Next, process those lines one-by-one, splitting out the appropriate values.
Then, you can find your array in
$output. Note that you should also add some validation to these lines and what not, to make sure they contain the data you expect. Also, if the lines optionally contain a space between the colon and the value, or a variable amount of whitespace, then split on the colon and usetrim()on the value, as appropriate.