1

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.

1
  • 1
    Show us what you have so far for code, please. Commented Oct 10, 2015 at 18:03

1 Answer 1

2

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;
}
Sign up to request clarification or add additional context in comments.

6 Comments

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 ;-)
@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.
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.
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.
@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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.