I get data from a textarea where a user has to enter a name one on each line. That data later gets split at the carriage return. Sometimes a user may add blank lines intentionally. How can I detect these lines and delete them? I’m using PHP. I dont mind using a regexp or anything else.
Incorrect Data
Matthew
Mark
Luke
John
James
Correct Data (Note blank lines removed)
Matthew
Mark
Luke
John
James
Using regex to eliminate blank lines before exploding (works well for any number of consecutive blank lines, also see next snippet):
Splitting with a regex:
Splitting without a regex:
Just feeling a tad creative today, pick your poison 🙂