1. <?php
  2. // Configuration file path
  3. $config_file = 'config.ini';
  4. // Default configuration values
  5. $max_rows = 100;
  6. $output_format = 'html';
  7. // Load configuration from file
  8. if (file_exists($config_file)) {
  9. $config = parse_ini_file($config_file);
  10. // Validate configuration values
  11. if (isset($config['max_rows']) && is_numeric($config['max_rows'])) {
  12. $max_rows = (int)$config['max_rows'];
  13. }
  14. if (isset($config['output_format']) && in_array($config['output_format'], ['html', 'json'])) {
  15. $output_format = $config['output_format'];
  16. }
  17. }
  18. // Function to limit output
  19. function limitOutput($data, $format = 'html') {
  20. $total_rows = count($data);
  21. if ($total_rows > $max_rows) {
  22. $start = 0;
  23. $end = $max_rows;
  24. $output = '';
  25. if ($format == 'html') {
  26. $output .= '<div class="data-table">';
  27. foreach (array_slice($data, $start, $end) as $row) {
  28. $output .= '<table><tr>';
  29. foreach ($row as $cell) {
  30. $output .= '<td>' . htmlspecialchars($cell) . '</td>';
  31. }
  32. $output .= '</tr></table>';
  33. }
  34. $output .= '</div>';
  35. } elseif ($format == 'json') {
  36. $output = json_encode(array_slice($data, $start, $end));
  37. }
  38. } else {
  39. if ($format == 'html') {
  40. $output = '';
  41. foreach ($data as $row) {
  42. $output .= '<table><tr>';
  43. foreach ($row as $cell) {
  44. $output .= '<td>' . htmlspecialchars($cell) . '</td>';
  45. }
  46. $output .= '</tr></table>';
  47. }
  48. } elseif ($format == 'json') {
  49. $output = json_encode($data);
  50. }
  51. }
  52. return $output;
  53. }
  54. // Example data (replace with your actual data)
  55. $data = [
  56. ['name' => 'Alice', 'age' => 30, 'city' => 'New York'],
  57. ['name' => 'Bob', 'age' => 25, 'city' => 'Los Angeles'],
  58. ['name' => 'Charlie', 'age' => 35, 'city' => 'Chicago'],
  59. ['name' => 'David', 'age' => 28, 'city' => 'Houston'],
  60. ['name' => 'Eve', 'age' => 32, 'city' => 'Phoenix'],
  61. ['name' => 'Frank', 'age' => 27, 'city' => 'Philadelphia'],
  62. ['name' => 'Grace', 'age' => 31, 'city' => 'San Antonio'],
  63. ['name' => 'Henry', 'age' => 29, 'city' => 'San Diego'],
  64. ['name' => 'Ivy', 'age' => 33, 'city' => 'Dallas'],
  65. ['name' => 'Jack', 'age' => 26, 'city' => 'San Jose'],
  66. ['name' => 'Kelly', 'age' => 34, 'city' => 'Austin'],
  67. ['name' => 'Liam', 'age' => 24, 'city' => 'Jacksonville'],
  68. ['name' => 'Mia', 'age' => 36, 'city' => 'Columbus'],
  69. ['name' => 'Noah', 'age' => 23, 'city' => 'Charlotte'],
  70. ['name' => 'Olivia', 'age' => 37, 'city' => 'Indianapolis'],
  71. ['name' => 'Peter', 'age' => 22, 'city' => 'San Francisco'],
  72. ['name' => 'Quinn', 'age' => 38, 'city' => 'Seattle'],
  73. ['name' => 'Ryan', 'age' => 21, 'city' => 'Denver'],
  74. ['name' => 'Sophia', 'age' => 39, 'city' => 'Washington D.C.'],
  75. ['name' => 'Thomas', 'age'

Add your comment