phreakk Posted November 2, 2011 Share Posted November 2, 2011 Hello everyone! I have been trying to figure out how I can go about this, and failing. I have a text file that lists records simply: ex: 99. I got in my friends "car", what a piece of crap... ex:100. It only goes 25mph. I need to parse it so that it uses the number to store in the table, or just remove everything and store the text to the end, using an auto increment for the line number(some span more than one line). The numbers cannot be used as a key either. The number of spaces after the number and period also varies, from 1-4. The text also contains other special characters such as quotes, numbers, commas, periods. Anyone have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/250333-parsing-help/ Share on other sites More sharing options...
gizmola Posted November 2, 2011 Share Posted November 2, 2011 Your description lacks clarity. Are you saying that every line starts with a number like: 3. 4. etc? Are you also saying you don't care about this number? Do some lines *not* begin with a number, thus indicating they are part of a previous line? There's way too much ambiguity in your description. Precision is important to getting good help. Here's my best guess, and I assume here you don't care about the number. I also assume you willl storing this in a mysql table with a varchar or text column, and that you know how to take care of that. I'm also assuming you know how to open the file and process each line in a loop. So my recommendation? Use explode on the '.' with the limit parameter of 2, which will split the string on the period after the line number: // $str contains the original line $splitstr = explode('.', $str, 2); echo trim($splitstr[1]); /// this is the remainder of line without the number portion, with whitespace at front and back removed Quote Link to comment https://forums.phpfreaks.com/topic/250333-parsing-help/#findComment-1284431 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.