Created
August 22, 2013 08:46
-
-
Save tridungpham/6304703 to your computer and use it in GitHub Desktop.
Test
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 | |
function is_right_format_col_1($val) { | |
// var_dump($val); | |
return is_numeric($val); | |
} | |
function is_right_format_col_2($val) { | |
return ! preg_match('/[^A-Za-z\s]/', $val); | |
} | |
function is_right_format_col_3($val) { | |
return in_array($val, array('trai', 'gai')); | |
} | |
function is_right_format_col_4($val){ | |
return is_numeric($val) && intval($val) > 0 && intval($val) < 200; | |
} | |
function is_right_format_col_5($val) { | |
return is_numeric($val) && (strlen($val) == 4); //bo sung them dkien | |
} | |
$f = fopen('data.txt', 'r'); | |
$first_line = true; | |
$total_column = 5; | |
echo '<table>'; | |
while($line = trim(fgets($f))) { | |
if ( $first_line ) { | |
$line = substr($line, 3); //strip BOM characters | |
$first_line = false; | |
} | |
$values = preg_split('/\s+/', $line); | |
if ( ! empty( $values) ) { | |
echo '<tr>'; | |
for($i = 1;$i <= $total_column;$i++) { | |
$cval = current($values); | |
if (call_user_func('is_right_format_col_' . $i, $cval)) { | |
echo '<td>' . $cval . '</td>'; | |
next($values); | |
} else { | |
echo '<td></td>'; | |
} | |
} | |
echo '</tr>'; | |
} | |
} | |
echo '</table>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment