tags:

views:

25

answers:

2

Hi I am new to PHP and hope someone can help me.

Sometimes the output from the executed shell script can be hundreds of lines long, the lines are separated with a <BR> (replaced \n in shell script) for formatted html output.

So I need to know how to make the output paginated, I looked at some other similar solutions here but I couldn't make them work as they did different things.

$url = $_POST["website"];
$safeurl = escapeshellarg($url);
#passthru("./check -n ".$safeurl);
$stuff=shell_exec("./webcheck -n ".$safeurl);

$webFile = ($url.'.txt');
$write = $stuff;
$fh = fopen($webFile, 'w') or die("can't open file");
fwrite($fh, $write);
fclose($fh);

$fh = fopen($webFile, "r") or die("can't open file");
$frstuff=fread($fh, filesize($webFile));
fclose($fh);
echo $frstuff;
A: 

Its not the best solution, but the easiest is going to be using javascript to do the pagination.

Try: http://plugins.jquery.com/project/pagination

Otherwise you could plugin a generic database pagination script and change the database adaptor to point to a file adaptor, where number of rows becomes number of lines.

Edit: provided better link

ae
this is spam it has links to trick you into clicking on ads
Kyoku
Why not just go to the source? http://plugins.jquery.com/project/pagination
pferate
Updated with a better link
ae
i found a better solution http://www.9lessons.info/2010/10/pagination-with-jquery-php-ajax-and.html
Kyoku
+1  A: 

If you try using exec with an additional parameter instead of shell_exec, you can get the output lines as an array rather than one long string.

$output = array();
exec("./webcheck -n $safeurl", $output);

// Inspect the contents of $output
var_dump($output);

Then you can iterate through that array ($output) as needed.

pferate