<?php
// Configuration file path
$config_file = 'config.ini';
// Default configuration values
$max_rows = 100;
$output_format = 'html';
// Load configuration from file
if (file_exists($config_file)) {
$config = parse_ini_file($config_file);
// Validate configuration values
if (isset($config['max_rows']) && is_numeric($config['max_rows'])) {
$max_rows = (int)$config['max_rows'];
}
if (isset($config['output_format']) && in_array($config['output_format'], ['html', 'json'])) {
$output_format = $config['output_format'];
}
}
// Function to limit output
function limitOutput($data, $format = 'html') {
$total_rows = count($data);
if ($total_rows > $max_rows) {
$start = 0;
$end = $max_rows;
$output = '';
if ($format == 'html') {
$output .= '<div class="data-table">';
foreach (array_slice($data, $start, $end) as $row) {
$output .= '<table><tr>';
foreach ($row as $cell) {
$output .= '<td>' . htmlspecialchars($cell) . '</td>';
}
$output .= '</tr></table>';
}
$output .= '</div>';
} elseif ($format == 'json') {
$output = json_encode(array_slice($data, $start, $end));
}
} else {
if ($format == 'html') {
$output = '';
foreach ($data as $row) {
$output .= '<table><tr>';
foreach ($row as $cell) {
$output .= '<td>' . htmlspecialchars($cell) . '</td>';
}
$output .= '</tr></table>';
}
} elseif ($format == 'json') {
$output = json_encode($data);
}
}
return $output;
}
// Example data (replace with your actual data)
$data = [
['name' => 'Alice', 'age' => 30, 'city' => 'New York'],
['name' => 'Bob', 'age' => 25, 'city' => 'Los Angeles'],
['name' => 'Charlie', 'age' => 35, 'city' => 'Chicago'],
['name' => 'David', 'age' => 28, 'city' => 'Houston'],
['name' => 'Eve', 'age' => 32, 'city' => 'Phoenix'],
['name' => 'Frank', 'age' => 27, 'city' => 'Philadelphia'],
['name' => 'Grace', 'age' => 31, 'city' => 'San Antonio'],
['name' => 'Henry', 'age' => 29, 'city' => 'San Diego'],
['name' => 'Ivy', 'age' => 33, 'city' => 'Dallas'],
['name' => 'Jack', 'age' => 26, 'city' => 'San Jose'],
['name' => 'Kelly', 'age' => 34, 'city' => 'Austin'],
['name' => 'Liam', 'age' => 24, 'city' => 'Jacksonville'],
['name' => 'Mia', 'age' => 36, 'city' => 'Columbus'],
['name' => 'Noah', 'age' => 23, 'city' => 'Charlotte'],
['name' => 'Olivia', 'age' => 37, 'city' => 'Indianapolis'],
['name' => 'Peter', 'age' => 22, 'city' => 'San Francisco'],
['name' => 'Quinn', 'age' => 38, 'city' => 'Seattle'],
['name' => 'Ryan', 'age' => 21, 'city' => 'Denver'],
['name' => 'Sophia', 'age' => 39, 'city' => 'Washington D.C.'],
['name' => 'Thomas', 'age'
Add your comment