3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class SearchStream { public static function findLines( $keyword, $file ) { $stream = stream_get_contents( $file ); $lines = explode( "n", $stream ); $foundLines = []; foreach( $lines as $line ) { if( strpos( $line, $keyword ) ) { array_push( $foundLines, rtrim($line) ); } } return $foundLines; } } $stream = fopen( 'php://memory', 'r+' ); fputs( $stream, "Hello, there!nHow are you today?nYes, you over there." ); rewind( $stream ); print_r( SearchStream::findLines( 'there', $stream ) );
Output for 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.1
Array ( [0] => Hello, there! [1] => Yes, you over there. )