PhpSnip.com

User Stats

Match line

return the first line in a given file containing the given string

Info

 Download  View Source (print view)
 Rating : 4.7  Views : 176

Source Code ( 18 lines )

function getline($file, $string) {

    /* return the first line in a given file containing the given string */

    $file_pointer = fopen("$file", "r");

    for ($i = 0; !feof($file_pointer); $i++) {
        $line = fgets($file_pointer, 1024);

        if (ereg($string, $line))
            break;

    }

    fclose($file_pointer);

    return $line;
}

Search

Subscribe

  Rss Feeds

Sponsors

Advertise