Q:

Display Error Messages From File In Codeigniter

On my controller I am trying to find multiple lines that start with specified words. 
$file = file(FCPATH . 'application/logs/log-' . date('Y-m-d') . '.php');
$data['debug_messages'] = $this->display_lines($file, 'DEBUG');
$data['informational_messages'] = $this->display_lines($file, 'INFO');

And the function display_lines
function display_lines($file, $str) {
    $lines = $file;
    foreach ($lines as $lineNumber => $line) {
        if (strpos($line, $str) !== false) {
            return $line;
        }
    }
}

When I view the out put it only displays one line of each and does not display multiple info and debug lines as showing in image
It should display more messages but for some reason displays only one line of each.

Question If there are multiple lines that starts with info, debug how can I get it to return the multiple lines for each info and debug?

Log File
INFO - 2016-07-28 21:41:43 --> Config Class Initialized
INFO - 2016-07-28 21:41:43 --> Hooks Class Initialized
DEBUG - 2016-07-28 21:41:43 --> UTF-8 Support Enabled
INFO - 2016-07-28 21:41:43 --> Utf8 Class Initialized
INFO - 2016-07-28 21:41:43 --> URI Class Initialized
INFO - 2016-07-28 21:41:43 --> Router Class Initialized
INFO - 2016-07-28 21:41:44 --> Output Class Initialized
INFO - 2016-07-28 21:41:44 --> Security Class Initialized
DEBUG - 2016-07-28 21:41:44 --> Global POST, GET and COOKIE data sanitized
INFO - 2016-07-28 21:41:44 --> Input Class Initialized
INFO - 2016-07-28 21:41:44 --> Language Class Initialized
INFO - 2016-07-28 21:41:44 --> Loader Class Initialized
INFO - 2016-07-28 21:41:44 --> Helper loaded: form_helper
INFO - 2016-07-28 21:41:44 --> Helper loaded: url_helper
INFO - 2016-07-28 21:41:44 --> Database Driver Class Initialized
DEBUG - 2016-07-28 21:41:44 --> Encryption: Auto-configured driver 'openssl'.

View
<div class="container">

    <div class="row">

        <div class="col-lg-12">

            <div class="page-header">
                <h4>Debug Messages</h4>
            </div>

            <textarea wrap="off" rows="15" readonly class="form-control"><?php echo $debug_messages; ?></textarea>

        </div>

    </div>

    <div class="row">

        <div class="col-lg-12">

            <div class="page-header">
                <h4>Informational Messages</h4>
            </div>

            <textarea wrap="off" rows="15" readonly class="form-control"><?php echo $informational_messages; ?></textarea>

        </div>

    </div>

</div>

A:

I might have misunderstood the question. You want all the lines but now you are only returning the first match, why dont you edit your function like so:
function display_lines($file, $str) {
    $lines = array();
    foreach ($file as $lineNumber => $line) {
        if (strpos($line, $str) !== false) {
            $lines[] = $line;
        }
    }

    return $lines;
}

