I have a sample string as shown below. In the string, how can I remove line ending with ( and remove line starting with ) and grab second word of every line?
This is some text (
some more text,
one line text,
more and more text available,
this one is even longer and even more text is available,
) this is the last line;
This is also some more text (
Second time some more text,
one line text second time ,
Once again more and more text available,
finally this one is even longer and even more text is available,
) this is the last line;
The string shown above comes from a text file. Can be either pasted in a textarea or a file could be uploaded and this text will be read from the file. So in the example shown above, expected output is:
some more text,
one line text,
more and more text available,
this one is even longer and even more text is available,
Second time some more text,
one line text second time ,
Once again more and more text available,
finally this one is even longer and even more text is available,
//words are
more
line
and
one
time
line
again
this
How to do the above in PHP?
You can use the
explode,array_map, andarray_filterfunctions to do what you want.First you have to define functions to filter out the ( and ) lines, and to extract the second word of each line.
Now that you have that, the rest is easy:
All done.
Incidentally, it’s clear you are trying to get type values from a
CREATE TABLEstatement – you might have to be a little more careful about how you parse that depending on your RDBMS.