New Lines and data from a network request

I am a true newbie.  I’ve been doing a lot of reading about coronalabs over the last few months, but have just started doing proof of concept work.  I have searched the forums, but haven’t found a solution that worked for me, which is why I am asking the question.

My plan is to have at least some data that needs to be displayed, provided by a remote source.  A website/php files backed with MySQL database.  I will be doing time/date stamping on the data so the data in its entirety won’t be fetched each time.  But I can’t for the life of me figure out how to place newlines into the data being fetched.  This data will be fetched with a networkrequest.

I have created newText sections where I specify both the height and width.  So they should be multiline segments.  But they just display the ‘\n’ and/or ‘\r’ that I add into the text, in the php file. 

Am I missing something?  Is it even possible to do this?  I can fetch it twice, concatonate a newline character in between each response and have that work just fine.  But it just won’t recognize it in the entire response.  I really don’t want to have to break each paragraph into its own table entry to fetch each and every time.

Also…  There are times where I suspect that I’ll have much more than one blurb or page worth of text/data to display.  Is there a way to scroll the data?  Is it just a matter of if the text overruns the height of the newText?

Thank you for any help you can provide!

suggest you “hardcode” a sample reply to determine if you’re getting the expected network response

does your response literally include ‘\n’ and/or ‘\r’ as two-character escape sequences?  (if so you’ll likely need to “unescape” them after receiving the response)  or does the response include the actual single-character control codes (0x0A and 0x0D) that those escape sequences encode?

in your network listener try adding something like this once you’ve gotten a response:

 for i=1,#event.response do print(event.response:byte(i)) end

then ask:  do you see any literal 10’s and 13’s in the output (control characters), or patterns of 92,110 and 92,114  (escaped \n \r)?

do you ‘hardcode’ the ‘\n’ and ‘\r’? or the content is from forms that have hidden ‘\n’ or ‘\r’. don’t know if i explane it well. in your database you see the ‘\n’ or ‘\r’? you don’t need them in the database, just do enters in the form normaly, it will put to the database with hidden ‘\n’ that in corona will transform that to normal ‘\n’. never had a problem with paragraphs from my php database. i tried hardcode the ‘\n’ and the problem that you referee appear. corona will think that the all the text until he finds the true ‘\n’ is a string. it will ignore the hardcode ‘\n’. hope you got the point.

ofc you can resolve this yourself with string manipulation in corona side. just check if ‘\n’ exists and break it from zero till it found the ‘\n’, start the counter from the ‘\n’ he found to the next ‘\n’ and go on…till EOF.

gsub()

I was hardcoding the output…  I don’t have access to the actual test code right now, but it was something like this:

\<?php print 'This is one line.\nAnd this is a second'; ?\>

When I would receive the response, it would literally print out the text for \n and keep it all as one line wrapping when it got to the limit of the area.

it’s your php:  use double-quotes

Ugh…  I forgot about that.  I typically don’t format my source html, so all of the strings I print/output are what they are.  I just use single quotes. 

Thank you!  I’ll try that this evening sometime.

Any guidance on how to make a large amount of text/response data scroll within the text area created?  I’m guessing there is something in the docs, but I couldn’t find anything and truthfully wasn’t sure what to search on.

if you want to scroll text in an area you have:

https://docs.coronalabs.com/api/library/widget/newScrollView.html

if you want large text in an area you still can use it with a bit of code change, but i think there is a code in forums to do that. if you don’t find it let me know i will post it here again.

suggest you “hardcode” a sample reply to determine if you’re getting the expected network response

does your response literally include ‘\n’ and/or ‘\r’ as two-character escape sequences?  (if so you’ll likely need to “unescape” them after receiving the response)  or does the response include the actual single-character control codes (0x0A and 0x0D) that those escape sequences encode?

in your network listener try adding something like this once you’ve gotten a response:

 for i=1,#event.response do print(event.response:byte(i)) end

then ask:  do you see any literal 10’s and 13’s in the output (control characters), or patterns of 92,110 and 92,114  (escaped \n \r)?

do you ‘hardcode’ the ‘\n’ and ‘\r’? or the content is from forms that have hidden ‘\n’ or ‘\r’. don’t know if i explane it well. in your database you see the ‘\n’ or ‘\r’? you don’t need them in the database, just do enters in the form normaly, it will put to the database with hidden ‘\n’ that in corona will transform that to normal ‘\n’. never had a problem with paragraphs from my php database. i tried hardcode the ‘\n’ and the problem that you referee appear. corona will think that the all the text until he finds the true ‘\n’ is a string. it will ignore the hardcode ‘\n’. hope you got the point.

ofc you can resolve this yourself with string manipulation in corona side. just check if ‘\n’ exists and break it from zero till it found the ‘\n’, start the counter from the ‘\n’ he found to the next ‘\n’ and go on…till EOF.

gsub()

I was hardcoding the output…  I don’t have access to the actual test code right now, but it was something like this:

\<?php print 'This is one line.\nAnd this is a second'; ?\>

When I would receive the response, it would literally print out the text for \n and keep it all as one line wrapping when it got to the limit of the area.

it’s your php:  use double-quotes

Ugh…  I forgot about that.  I typically don’t format my source html, so all of the strings I print/output are what they are.  I just use single quotes. 

Thank you!  I’ll try that this evening sometime.

Any guidance on how to make a large amount of text/response data scroll within the text area created?  I’m guessing there is something in the docs, but I couldn’t find anything and truthfully wasn’t sure what to search on.

if you want to scroll text in an area you have:

https://docs.coronalabs.com/api/library/widget/newScrollView.html

if you want large text in an area you still can use it with a bit of code change, but i think there is a code in forums to do that. if you don’t find it let me know i will post it here again.