0

I've got a problem here I know what I want to do but cant get around coding it, I've already opened a text document using my PHP code now I want to skip the first 59 lines of the document then send the first 4 strings of every sentence that follow after skipping those 59 lines to a database which I've already created. I've already written down the code that will skip that opens the document and skips the first 59 line now all I need to do is send the first 4 strings of every line to the database. Here is my code.

$url = 'C:\portsdocx.txt'; //my text document

$file = file_get_contents($url) //opens up my document
or die("Could Not Open The TEXT File<hr /> " . mysql_error());
$file = implode("\n", array_slice(explode("\n", $file), 59));// skips the first 59 lines

And the the code that says explode the first 4 strings of every line comes here which is what I really want!!! I know I should use the explode function but cant really figure out how.

And then the data gets sent to my database.

here's the code.

while ($data = file_get_contents($file, 10000)) 
{

    mysql_query("INSERT into registry
    ('ServiceName','PortNumber','TransportProtocol','Description')
    VALUES('".$data['0']."','".$data['1']."','".$data['2']."','".$data['3']."')");
}

Thanks in advance.

1
  • What is the question? I'm not sure I understand. Commented Oct 19, 2011 at 8:34

1 Answer 1

1

yep, use explode:

$line = explode(' ', $data, 4);
mysql_query("INSERT into registry
    ('ServiceName','PortNumber','TransportProtocol','Description')
    VALUES('".$line['0']."','".$line['1']."','".$line['2']."','".$line['3']."')");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.