Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.
Forgot Password?
Navigation

Parsing A Text File

Last updated on 4 years ago
G
GrimlochSenior Member
Posted 4 years ago
OK thanks; I'll take care of it.
A
afosterSenior Member
Posted 4 years ago
Yes, I was able to get some help elsewhere so I am good to go. Just got it set it up today, so you can delete this thread.

Grimloch, tried to send you a private message but it would not go through because your inbox is full.
G
GrimlochSenior Member
Posted 4 years ago
Fred; if you have figured this out let us know if not; email me and I can help you with it.
A
afosterSenior Member
Posted 4 years ago
Thank you so much for your response Chan...unfortunately much of what you wrote is way over my head. I do have a comma after each piece of data so the implode should work for me. I will do some further googling to see if I can find some sample code that may lead me to my solution. I should mention that the data in the text file are email addresses separated by a comma.
Edited by afoster on 14-07-2022 16:27, 4 years ago
C
ChanSuper Admin
Posted 4 years ago
I'm not sure what are you looking for in responses, or where you encountered difficulty in solving, so here's my few grain of salt in this.

If you are splitting the text separated by commas only:
$sentences = explode(',', $text);


What problem I see here, is that your text cannot contain a single comma since the comma symbol is used as a delimiter, which 9/10 of the chance won't work nicely. I use multiple commas in a single sentence at times.

Then, if you want to join up the $sentences array into a subgroup, you can group them up further using array_chunk function

Then I think it's best not to work with <td>, those are for excel kind of use for storing hard statistical data use only where you need to search value by columns. Secondary, they are not responsive to screen sizes.

By way of splitting them into 2 columns, you have few choices to do this.

1. Using Bootstrap
<div class='row'><div class='col-xs-12 col-sm-6'>".implode("</div><div class='col-xs-12 col-sm-6'>", $sentences)."</div></div>


2. Using Grid CSS
<styles>
.grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap:15px;
}
<div class="grid"><div>".implode("</div><div>", $sentences)."</div></div>


If you do not want to limit to 2 columns, you can go for a more linear flex type of div container. It is when we need content to stack downwards to next row automatically once the content goes off screen.
A
afosterSenior Member
Posted 4 years ago
I have a text file containing data in one continuous line separated by a comma (,). I'm looking for php code that will parse that data into either one or preferably two columns. All I have been able to do at this point is pull the data into a <td> that displays the data as a continuous line. Any input would be appreciated.
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
Moderator: Support Team
Users who participated in discussion: afoster, Chan, Grimloch