Read a blob field line by line

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paulin1
Forum Newbie
Posts: 1
Joined: Tue Jan 12, 2016 9:58 pm

Read a blob field line by line

Post 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
User avatar
Christopher
Site Administrator
Posts: 13592
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Read a blob field line by line

Post 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) {
(#10850)
Post Reply