File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -175,15 +175,40 @@ public function tell(): int
175175 }
176176
177177 /**
178- * Gets line from file pointer
178+ * Gets line from a file pointer
179179 * @return string|false
180180 */
181- public function getLine (): string |bool
181+ public function getLine (): string |false
182182 {
183- $ line = fgets ($ this ->resource );
184- return trim ($ line );
183+ return fgets ($ this ->resource );
185184 }
186185
186+ /**
187+ * Will get output between a from and to line number
188+ *
189+ * @param int $from
190+ * @param int $to
191+ * @return string
192+ */
193+ public function getLines (int $ from , int $ to ): string
194+ {
195+ $ this ->rewind ();
196+ $ lineNo = 0 ;
197+ $ out = '' ;
198+ while (($ line = $ this ->getLine ()) !== false ) {
199+ ++$ lineNo ;
200+ if ($ lineNo < $ from ) {
201+ continue ;
202+ }
203+ if ($ lineNo > $ to ) {
204+ break ;
205+ }
206+ $ out .= $ line ;
207+ }
208+ return $ out ;
209+ }
210+
211+
187212 /**
188213 * Returns true if the stream is at the end of the stream.
189214 * @return bool
You can’t perform that action at this time.
0 commit comments