You are here

function array_to_plaintext_table in Webform view 7

Same name and namespace in other branches
  1. 7.4 webform_view.inc \array_to_plaintext_table()

Rendering function to emulate table layout.

Parameters

array $rows: Structured data. A two-dimensional array.

Return value

string HTML rendering of the input.

1 call to array_to_plaintext_table()
theme_webform_display_view in ./webform_view.inc
Format the output of data for this component.

File

./webform_view.inc, line 509
Additional component for webform that allows views to be used as embeddable elements.

Code

function array_to_plaintext_table($rows) {
  $cols = array();

  // Count the col widths first.
  foreach ($rows as $delta => $row) {
    foreach ($row as $col => $cell) {
      $cols[$col] = max(@$cols[$col], strlen($cell), strlen($col));
    }
  }

  // Now format.
  $lines = array();
  $printf_format = '';

  // Build the string template.
  foreach ($cols as $colwidth) {
    $printf_format .= "%-{$colwidth}s : ";
  }

  // First the header row.
  $lines[] = call_user_func_array('sprintf', array(
    'format' => $printf_format,
  ) + array_keys($cols));
  foreach ($rows as $row) {
    $lines[] = call_user_func_array('sprintf', array(
      'format' => $printf_format,
    ) + $row);
  }
  return implode("\n", $lines);
}