Created
August 16, 2012 17:25
-
-
Save ekka21/3371834 to your computer and use it in GitHub Desktop.
php: convert strings to table fixed columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @Desc: Convert str1,str2,str3,str4,str5,....... to fix table columns | |
* @param string, delimiter, number of column | |
* @return Table markup fix columns | |
*/ | |
function pre_table($str, $del = ',', $numCols = '3'){ | |
$cnt = 0; | |
$arr = explode($del,$str); | |
$out_str = "<table width='100%'>"; | |
$cnt=0; | |
for ($cnt=0;$cnt<count($arr); $cnt++) | |
{ | |
if ($cnt % $numCols == 0) | |
{ | |
if ($cnt > 0) $out_str .= "</tr>"; | |
$out_str .= "<tr valign='top'>"; | |
} | |
$out_str .= "<td>".$arr[$cnt]."</td>"; | |
} | |
while ($cnt % $numCols != 0) | |
{ | |
$out_str .= "<td> </td>"; | |
$cnt++; | |
} | |
$out_str .= "</tr></table>"; | |
return $out_str; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment