Jump to content

Parsing Help!!


phreakk

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.