jingjihui 发表于 2017-3-29 10:36:45

php,几个有用的函数介绍

strtr
  strtr() 函数转换字符串中/数组中特定的字符。

<?php
$arr = array("Hello" => "Hi", "world" => "earth");
echo strtr("Hello world",$arr)
;
?>
  输出:

Hi earth
The file_put_contents() writes a string to a file.
file_put_contents()函数的作用是:将一个字符串写入文件。


var_export
  (PHP 4 >= 4.2.0, PHP 5)


var_export -- 输出或返回一个变量的字符串表示

  



描述

  
mixed var_export
( mixed expression [, bool return])



  
      此函数返回关于传递给该函数的变量的结构信息,它和
var_dump()
类似,不同的是其返回的表示是合法的
PHP 代码。

  
您可以通过将函数的第二个参数设置为
TRUE

,从而返回变量的表示。



[*]
function cache_write($file, $string, $type = 
'array'
)  

[*]
{  
[*]
    if
(is_array($string))  

[*]
    {  
[*]
        $type = strtolower($type);  
[*]
        if
($type == 
'array'
)  

[*]
        {  
[*]
            $string = "<?php\n return "
.var_export($string,TRUE).
";\n?>"
;  

[*]
        }  
[*]
        elseif($type == 'constant'
)  

[*]
        {  
[*]
            $data=''
;  

[*]
            foreach($string as $key => $value) $data .= "define('"
.strtoupper($key).
"','"
.  

[*]
addslashes($value)."');\n"
;  

[*]
            $string = "<?php\n"
.$data.
"\n?>"
;  

[*]
        }  
[*]
    }  
[*]
    $strlen = file_put_contents(PHPCMS_CACHEDIR.$file, $string);  
[*]
    chmod(PHPCMS_CACHEDIR.$file, 0777
);  

[*]
    return
 $strlen;  

[*]


页: [1]
查看完整版本: php,几个有用的函数介绍