StudioWorks Posted March 8, 2017 Share Posted March 8, 2017 Hello everybody,I am kind of new to this so I am hoping that you can give me a hand. The task is this:I have 5 .txt files, each file contains 10 lines of text. I have to randomly select one line from each file and the these generated lines have to be sent through email to two email addresses.Can you please provide some pointers ?Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/303398-need-some-help-pick-random-lines-from-text-files-email/ Share on other sites More sharing options...
Barand Posted March 8, 2017 Share Posted March 8, 2017 (edited) Two functions you might find useful: file() array_rand() or shuffle() Edited March 8, 2017 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/303398-need-some-help-pick-random-lines-from-text-files-email/#findComment-1543931 Share on other sites More sharing options...
ginerjm Posted March 8, 2017 Share Posted March 8, 2017 A better approach which would require more setup work would be to create a table that has an categ/file code to group the 10 lines from each of the 5 files and another "seq" number to identify each line in that categ/file code. Then you simply use the rand function to pick a number from 1 to n for each of your categs and perform a query that selects the categ/seq values that match the random ones selected. Then you do the email. Your current method involves having to open and read each file separately to get your data. Building the db would be much easier to work with and allows for very easy changes to the data to add or remove lines. Just my $.02 Quote Link to comment https://forums.phpfreaks.com/topic/303398-need-some-help-pick-random-lines-from-text-files-email/#findComment-1543934 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.