I am storing a text datatype in a database that contains newlines (cr + lf). It is accessed by, for example, $row['mytext']. How can I read $row['mytext'] line by line to do some parsing prior to outputting to html? I know how to do this with a file but have never done it with text from a database.
-
1Show us what you have so far for code, please.Shawn Mehan– Shawn Mehan2015-10-10 18:03:46 +00:00Commented Oct 10, 2015 at 18:03
Add a comment
|
1 Answer
Once you have $row['mytext'] it is just a string so you can just explode on new lines and then iterate through the array.
Example:
$string = 'line 1
line2';
foreach(explode("\n", $string) as $line) {
echo $line;
}
6 Comments
Funk Forty Niner
Sorry to hear about that "rabbit" hole you fell into earlier Chris. I knew that question was going nowhere. Maybe this will make up for it. You have a LOT more patience than I do ;-)
chris85
@Fred-ii- thanks, I had a feeling I was walking into that on the first comment but figured it couldn't go as far as it did.
Funk Forty Niner
You're welcome Chris. Plus the fact that
db.php was a Pandora's box and the rest of whatever's in their db, wow. I swear to you, I'll bet you would be a great "cactus grower" ;-) Cheers man.Funk Forty Niner
Oh btw, that question, was a repost of stackoverflow.com/questions/33069170/… - Had I checked first, I would have closed it from the get-go.
chris85
@Fred-ii- hah, I'll have to look into this cactus growing. Looks like a similar outcome on that question as well. OP needs to learn to debug; never going to be able to resolve their issues.
|