Page 1 of 1

Read a blob field line by line

Posted: Tue Jan 12, 2016 10:04 pm
by paulin1
How can I read a blob field that has been pulled from the database and has formatted text?
I need to be able to read line by line in order to populate a table, basically get the contents from each line. thanks

Re: Read a blob field line by line

Posted: Wed Jan 13, 2016 11:36 am
by Christopher
Probably the easiest is to split the text on newlines into an array. The simplest would be:

Code: Select all

$lines = explode("\n", $text);     // or \r
If line endings can be mixed then more complicated:

Code: Select all

$lines = preg_split("/((\r?\n)|(\r\n?))/", $text);
Then just

Code: Select all

 foreach($lines as $line) {