| is_int(1) | true | 
| is_int(1.0) | false | 
| is_int('1') | false | 
| is_numeric(1) | true | 
| is_numeric(1.0) | true | 
| is_numeric('1') | true | 
| is_numeric(123.456) | true | 
| ctype_digit('1') | true | 
| ctype_digit('1.0') | false | 
| ctype_digit('1abc') | false | 
| ctype_digit(1) | false | 
| ctype_digit(strval(1)) | true | 
| preg_match('/^\d+$/', '1234') | true | 
| preg_match('/^\d+$/', 'toto') | false | 
| preg_match('/^\d+$/', ' 12 ') | false | 
<?php
/**
 * @file est_un_nombre_entier.php
 * @brief Ce script essaie différentes façons de tester un nombre entier.
 *
 * @author hughes monget
 * @see http://monget.com/
 */
$arr_str_code = <<<CODE
is_int(1)
is_int(1.0)
is_int('1')
is_numeric(1)
is_numeric(1.0)
is_numeric('1')
is_numeric(123.456)
ctype_digit('1')
ctype_digit('1.0')
ctype_digit('1abc')
ctype_digit(1)
ctype_digit(strval(1))
preg_match('/^\d+$/', '1234')
preg_match('/^\d+$/', 'toto')
preg_match('/^\d+$/', ' 12 ')
CODE;
$arr_str_code = explode("\n", $arr_str_code);
$arr_str_code = array_map('trim', $arr_str_code);
$arr_str_code = array_filter($arr_str_code, create_function('$s', 'return !!$s;'));
echo '<pre><table border="1">';
foreach ($arr_str_code as $str_code)
{
    eval('$bool_test = (bool)'.$str_code.';');
    echo '<tr><td>',htmlspecialchars($str_code),'</td><td>';
    if ($bool_test)
        { echo '<span style="color: ForestGreen">true</span>'; }
    else
        { echo '<span style="color: FireBrick">false</span>'; }
    echo '</td></tr>';
}
echo '</table></pre>';
echo '<hr />';
highlight_file(__FILE__);