Hello I just read a document using PHP and I need to skip the first 58 lines of that document and then start sending the data that follows from those lines to my database. How do I go about skipping the first 58 lines of the document.

I really need help thank you in advance.

Recommended Answers

All 5 Replies

Maybe you are looking for:

$str = implode("\n", array_slice(explode("\n", $str), 58));

while $str is your document content and 58 the lines to be skipped

-Agarsia

Agarsia thanks I'll try it out.

thanks Argasia it works really appreciate it.

Be careful when using code like that with large files. That relies on your entire file being first read into memory.

The better way to do this would be to iterate over the file line by line.

<?php
$it = new LimitIterator( new SplFileObject( 'sometextfile.txt' ), 57 );

foreach( $it as $line ){
  echo $line;
}

http://www.php.net/manual/en/class.splfileobject.php
http://www.php.net/manual/en/class.limititerator.php

Okay, mschroeder your help is really appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.