class="php" name="code">function se_search_line($filename, $pattern) { if (is_readable($filename)) $lines = file($filename); else return ''; $rs = array(); if (!empty($lines)) { foreach ($lines as $key => $value) { if (preg_match($pattern, $value)) { $rs[intval($key) + 1] = $value; } } } if ( !empty($rs) ) { $sp = PHP_SAPI === 'cli' ? "\n" : "<br>"; foreach ($rs as $line => $value) { //echo "#line: {$line}#{$sp}"; echo "{$value}"; } } } // demo se_search_line(__FILE__, "/lines/");
?