I have a text file in which each line is an entry.
each line has certain words separated by space and 2 -3 words at the end of the entry with brackets
eg.
asd asdasd asdasd {m} [jsbbsdfb]
how do I get the following result in php
$data[0]="asd asdasd asdasd"
$data[1]= "{m}"
$data[2]= "[jsbbsdfb]"
You can use
substringandstrposto find the right parts or you can usepreg_match(regular expressions), both have their own (dis)advantages. Usingpreg_matchyou can do this is as little as one line, but it is relatively slow and not as easy to use. I would do something like this:The other answer provided above, by wired00, are correct too, but only if each line is exactly the same in length (i.e. the same amount of words an spaces). The answer by check123 is not a correct answer to your question.
See strauberry’s answer for the regular expression which I mentioned in above.