Michael_Baxter Posted January 23, 2017 Share Posted January 23, 2017 hi, On my website I have a form with a single text area and a submit button, the user will come to my site with a report of points and stats from hosting a tournament online, see attached picture for details of the report once they hit submit the form posts to my processing page, in the processing page I take all the information I need from the beginning of the report this was kind of easy to do, the part I seem to be struggling with is splitting the array at this point. I have exploded each line from my report into an array $records, what I need to do now is, take everything from the line "START POINTS" down to the line "STOP POINTS" from the main array into a new array so that I can get the new array and use a foreach loop on it to separate the player name from player points I already have the foreach loop setup ready as I had this all setup once but I was not getting the information from the top of the report now I need that information so my original foreach does not work Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted January 23, 2017 Share Posted January 23, 2017 You could use the strpos() function to locate the two strings. And then use substr() to get the content between the two points. Quote Link to comment Share on other sites More sharing options...
Michael_Baxter Posted January 23, 2017 Author Share Posted January 23, 2017 I did think about that to start with apart from $records is an array each line in the report from my screenshot I uploaded here is an individual index inside of records so $records[0]; would equals to "Nojoks's Tourney Bracket Tool Version 1.2.1.84 $records[1] equals to "Tournament 3/5 Backgammon 1.00pm" and so on. so I don't think strops would really work here every single line from that report has been exploded into an array that's why I need to get access to line 19 then I can run a for each loop on the lines after that Quote Link to comment Share on other sites More sharing options...
Barand Posted January 23, 2017 Share Posted January 23, 2017 There are several things in this job that can lead to insanity. One of them is accepting free-form text as input. It only takes a small spelling mistake (like your "strops" above) and the whole thing collapses like a house of cards. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted January 24, 2017 Share Posted January 24, 2017 I did think about that to start with apart from $records is an array each line in the report from my screenshot I uploaded here is an individual index inside of records... With each line split into an array, you could loop through the array looking for the start point. Then store each of the following lines in a separate variable until the stop point is reached. There are several things in this job that can lead to insanity. One of them is accepting free-form text as input. It only takes a small spelling mistake (like your "strops" above) and the whole thing collapses like a house of cards. Yep, that would be problematic. Quote Link to comment Share on other sites More sharing options...
Solution Michael_Baxter Posted January 25, 2017 Author Solution Share Posted January 25, 2017 in the end I have used array slice to fix this issue, I took array slice from index 20 then a foreach loop on the new array from the slice with the final argument as -1 to remove the stop points line if copy and paste would work on this forum I would show you my final code Quote Link to comment 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.