is_numeric()を使っても、質問者さまが望む結果にはならないです。
なぜなら、ピリオド・コンマ・ダッシュも”数字”とみなされるからです。
なので代わりに、**ctype_digit()**を使いましょう。
`$test_number = '123.4';
$test_number2 = '12345';
echo ctype_digit($test_number) ? $test_number . ' is only digits' : $test_number . ' is not only digits';
echo ctype_digit($test_number2) ? $test_number2 . ' is only digits' : $test_number2 . ' is not only digits';
// output:
// 123.4 is not only digits
// 12345 is only digits`
まずは正規表現を避けて的確なツールを使うことをおすすめします。
あと、捕捉ですがctype_digit() は、整数でチェックするときに偽になる可能性があります。
PHPのマニュアルから:
ctype_digit( '42' ); // true ctype_digit( 42 ); // false - ASCII 42 is the * symbol
このコードは状況によりけりですが、質問者さまのケースですと、$_GETの変数をバリデートして全てstringになるので影響はありません。
【参考】
・ str_pad(): http://us1.php.net/str_pad
・ ctype_digit(): http://us2.php.net/manual/ja/function.ctype-digit.php
↓全てあわせたら・・・完璧のはずです^^!
if (ctype_digit($getuname) == true) { $getuname = str_pad($getuname, 5, 0, STR_PAD_LEFT); }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。