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.
Not a member yet? Click here to register.
Forgot Password?

Parsing A Text File

Asked Modified Viewed 1,100 times
A
afoster
A
  • Senior Member, joined since
  • Contributed 725 posts on the community forums.
  • Started 128 threads in the forums
  • Started this discussions
asked
Senior Member

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.
0 replies

5 posts

C
Chan
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,841 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
answered
Super Admin

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.
0 replies
A
afoster
A
  • Senior Member, joined since
  • Contributed 725 posts on the community forums.
  • Started 128 threads in the forums
  • Started this discussions
answered
Senior Member

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,
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Answered 2 questions
answered
Senior Member

Fred; if you have figured this out let us know if not; email me and I can help you with it.
0 replies
A
afoster
A
  • Senior Member, joined since
  • Contributed 725 posts on the community forums.
  • Started 128 threads in the forums
  • Started this discussions
answered
Senior Member

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.
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Answered 2 questions
answered
Senior Member

OK thanks; I'll take care of it.
0 replies

Category Forum

General Discussion

Statistics

  • Views 0 views
  • Posts 5 posts
  • Votes 0 votes
  • Topic users 3 members

3 participants

A
A
  • Senior Member, joined since
  • Contributed 725 posts on the community forums.
  • Started 128 threads in the forums
  • Started this discussions
C
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,841 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
G
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Answered 2 questions

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet