cmfcmf / column-width-calculator
使用PHP计算“完美”的表格列宽度。
1.0.0
2014-06-25 18:43 UTC
Requires
- php: >=5.3
This package is auto-updated.
Last update: 2024-09-24 05:00:12 UTC
README
使用PHP计算“完美”的表格列宽度,基于我在StackOverflow上的问题和@watcher的答案。
如何使用
$rows
需要是一个行数组。每个 $row
需要是一个单元格数组。每个 $cell
需要包含单元格的内容。
<?php /** * @param array $rows An array of rows, where each row is an array of cells containing the cell content. * @param bool $html Whether or not the rows contain html content. This will call html_entity_decode. * @param bool $stripTags Whether or not to strip tags (only if $html is true). * @param int $minPercentage The minimum percentage each row must be wide. * @param null $customColumnFunction A custom function to transform a cell's value before it's length is measured. */ $columnWidthCalculator = new Cmfcmf\ColumnWidthCalculator($rows); /** * Calculate the column widths. * * @return array * * Explanation of return array: * - $columnSizes[$colNumber]['percentage'] The calculated column width in percents. * - $columnSizes[$colNumber]['calc'] The calculated column width in letters. * * - $columnSizes[$colNumber]['max'] The maximum column width in letters. * - $columnSizes[$colNumber]['avg'] The average column width in letters. * - $columnSizes[$colNumber]['raw'] An array of all the column widths of this column in letters. * - $columnSizes[$colNumber]['stdd'] The calculated standard deviation in letters. * * INTERNAL * - $columnSizes[$colNumber]['cv'] The calculated standard deviation / the average column width in letters. * - $columnSizes[$colNumber]['stdd/max'] The calculated standard deviation / the maximum column width in letters. */ $columnSizes = $columnWidthCalculator->calculateWidths();
许可证
GPLv2,请参阅LICENSE文件。