Number is octal?
Simple and easy:
<?php
function is_octal($x) {
return decoct(octdec($x)) == $x;
}
echo is_octal(077); // true
echo is_octal(195); // false
?>
Thanks
[]'s
(PHP 4, PHP 5, PHP 7, PHP 8)
octdec — 8 進数を 10 進数に変換する
$octal_string
): int|float
octal_string
により指定された 8 進数を
10 進数表現した数値を返します。
octal_string
変換したい 8 進文字列。
octal_string
に無効な文字を与えても、静かに無視されます。
PHP 7.4.0 以降では、無効な文字を与えることは推奨されません。
octal_string
を 8 進で表した値を返します。
バージョン | 説明 |
---|---|
7.4.0 | 無効な文字を与えると、非推奨の警告が出るようになりました。 結果は不正な文字がなかったかのように計算されます。 |
例1 octdec() の例
<?php
echo octdec('77') . "\n";
echo octdec(decoct(45));
?>
上の例の出力は以下となります。
63 45
注意:
この関数は、プラットフォームの int 型に収まらない大きな数も変換できます。 その場合、結果は float で返します。
Number is octal?
Simple and easy:
<?php
function is_octal($x) {
return decoct(octdec($x)) == $x;
}
echo is_octal(077); // true
echo is_octal(195); // false
?>
Thanks
[]'s
The 'S' flag for Unix file access rights is badly computed in the above sample.
If the corresponding 'x' bit (exec) is not set, and the 's' bit (setgid/setuid/sticky) is set, then the flag should not be displayed as and uppercase 'S', but as a lower case 's'. Also the sticky bit (mainly used for folders with public right access rights such as /tmp to protect against deletion by non owner) is badly named ("text"?).
Calling the sticky bit "text" is not erroneous: On UNIX back in 1974, it instructed the operating system to retain the text segment of the program in swap space after the process exited. This speeded subsequent executions by allowing the kernel to make a single operation of moving the program from swap to real memory.