f::read PHP Method

read() static public method

Reads the content of a file
static public read ( string $file, mixed $parse = false ) : mixed
$file string The path for the file
$parse mixed if set to true, parse the result with the passed method. See: "str::parse()" for more info about available methods.
return mixed
    static function read($file, $parse = false)
    {
        $content = @file_get_contents($file);
        return $parse ? str::parse($content, $parse) : $content;
    }

Usage Example

Example #1
0
 public static function extract($file, $line)
 {
     $content = f::read($file);
     $lines = preg_split('/\\r\\n|\\n|\\r/', $content);
     $begin = $line - 5;
     if ($begin < 0) {
         $begin = 0;
     }
     $end = 10;
     $lines = array_slice($lines, $begin, $end);
     $html = '';
     $n = $begin + 1;
     foreach ($lines as $l) {
         if (empty($l)) {
             $l = ' ';
         }
         $num = '<span class="code-line-number">' . $n . '</span>';
         if ($n == $line) {
             $html .= '<span class="code-line code-line-highlighted">' . $num . htmlspecialchars($l) . '</span>';
         } else {
             $html .= '<span class="code-line">' . $num . htmlspecialchars($l) . '</span>';
         }
         $n++;
     }
     return $html;
 }
All Usage Examples Of f::read