$value = '\\40';
file_put_contents('o.txt',$value);
file_put_contents('o2.txt',var_export($value,true));
D:\test>php str.php
D:\test>cat o.txt
\40
D:\test>cat o2.txt
'\\40'
5 个解决方案
#1
var_export($value, true)
returns the string declaration value '\\40'
while just $value
returns the interpreted value of that declaration, thus \40
.
var_export($ value,true)返回字符串声明值'\\ 40',而$ value返回该声明的解释值,因此\ 40。
#2
Because var_export outputs or returns a parsable string representation of a variable
因为var_export输出或返回变量的可解析字符串表示形式
http://de.php.net/manual/en/function.var-export.php
Your code works perfectly. ;) Does just what it is expected to.
你的代码完美无缺。 ;)是否符合预期。
#3
The value of $value is '\40' (that is backslash, four, zero). When you just type it, this is what you get.
$ value的值是'\ 40'(即反斜杠,四,零)。当你输入它时,这就是你得到的。
var_export
gives you valid php code, in which you need to backslash the backslash, as you did yourself in the first line of code.
var_export为您提供有效的PHP代码,您需要在反斜杠中反斜杠,就像您在第一行代码中所做的那样。
Does that make sense?
那有意义吗?
#4
Because the output from var_export is encoded so you could put the result into a PHP file and include it or pass it to a call to eval. $value = \40 as o.txt shows. But if you were to say $x = eval(file_get_contents('o2.txt')); x would also = \40.
因为var_export的输出是经过编码的,所以您可以将结果放入PHP文件中并包含它或将其传递给eval调用。 o.txt显示$ value = \ 40。但是如果你要说$ x = eval(file_get_contents('o2.txt')); x也将= \ 40。
#5
$value = '\40';
$ value ='\ 40';
really means '\40', the first "\" escapes the second.
真的意思是'\ 40',第一个“\”逃脱了第二个。
var_export -- Outputs or returns a parsable string representation of a variable
var_export - 输出或返回变量的可解析字符串表示形式
var_export adds a "\" so it is escaped and parsable:
var_export添加一个“\”,以便它被转义和解析:
'\\40'
#1
var_export($value, true)
returns the string declaration value '\\40'
while just $value
returns the interpreted value of that declaration, thus \40
.
var_export($ value,true)返回字符串声明值'\\ 40',而$ value返回该声明的解释值,因此\ 40。
#2
Because var_export outputs or returns a parsable string representation of a variable
因为var_export输出或返回变量的可解析字符串表示形式
http://de.php.net/manual/en/function.var-export.php
Your code works perfectly. ;) Does just what it is expected to.
你的代码完美无缺。 ;)是否符合预期。
#3
The value of $value is '\40' (that is backslash, four, zero). When you just type it, this is what you get.
$ value的值是'\ 40'(即反斜杠,四,零)。当你输入它时,这就是你得到的。
var_export
gives you valid php code, in which you need to backslash the backslash, as you did yourself in the first line of code.
var_export为您提供有效的PHP代码,您需要在反斜杠中反斜杠,就像您在第一行代码中所做的那样。
Does that make sense?
那有意义吗?
#4
Because the output from var_export is encoded so you could put the result into a PHP file and include it or pass it to a call to eval. $value = \40 as o.txt shows. But if you were to say $x = eval(file_get_contents('o2.txt')); x would also = \40.
因为var_export的输出是经过编码的,所以您可以将结果放入PHP文件中并包含它或将其传递给eval调用。 o.txt显示$ value = \ 40。但是如果你要说$ x = eval(file_get_contents('o2.txt')); x也将= \ 40。
#5
$value = '\40';
$ value ='\ 40';
really means '\40', the first "\" escapes the second.
真的意思是'\ 40',第一个“\”逃脱了第二个。
var_export -- Outputs or returns a parsable string representation of a variable
var_export - 输出或返回变量的可解析字符串表示形式
var_export adds a "\" so it is escaped and parsable:
var_export添加一个“\”,以便它被转义和解析:
'\\40'