tail/tail.php

<?php header('content-type: text/plain; charset=utf-8');

// Normalize and dump text in a tmp file
$f = tmpfile();
fwrite($f, normalize($_POST['text']));

// Tail it
include 'tail.function.php';
$out = tail($f, (int) $_POST['lines'], (int) $_POST['buffer']);

// Output
if(isset($_POST['nl']))
	echo str_replace("\n", " \\n\n", $out);
else
	echo $out;

function normalize($s)
{
	$s = str_replace("\r\n", "\n", $s);
	$s = str_replace("\r", "\n", $s);
	return $s;
}