将'0777'字符串更改为0777八进制 [英] Change '0777' string to 0777 octal LITERALLY

查看:216
本文介绍了将'0777'字符串更改为0777八进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码就像

$perm = "0777"; //this is fetch from the database
chmod("myFolder/", $perm);

但是$ perm的值不是八进制,如何将变量的数据类型更改为八进制?甚至可以用另一种方法

but the value of $perm is not in octal, how can I change the data type of the variable to octal? even an alternative method will do

推荐答案

如前所述,没有八进制数字类型. chmod函数将第二个参数作为整数接收. $perm的隐式转换不假定数字为八进制.因此,您需要使用适当的函数将八进制字符串"转换为整数.

As it was mentioned, there is no octal number type. And chmod function receive the second param as integer number. Implicit conversion of $perm does not assume that number is octal. So, you need convert your "octal string" to integer by using appropriate function.

只需使用 octdec 函数

$perm = "0777"; //this is fetch from the database
chmod("myFolder/", octdec($perm));

intval

chmod("myFolder/", intval($perm, 8));

P.S.

var_dump('0644' == 0644);             // bool(false)
var_dump(intval('0644') == 0644);     // bool(false)
var_dump(decoct('0644') == 0644);     // bool(false)

var_dump(octdec('0644') == 0644);     // bool(true)
var_dump(intval('0644', 8) == 0644);  // bool(true)

这篇关于将'0777'字符串更改为0777八进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆