`

php,几个有用的函数介绍

    博客分类:
  • 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

描述

mixed var_export ( mixed expression [, bool return])

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

您可以通过将函数的第二个参数设置为 TRUE ,从而返回变量的表示。

 

  1. function cache_write($file, $string, $type =  'array' )  
  2. {  
  3.     if (is_array($string))  
  4.     {  
  5.         $type = strtolower($type);  
  6.         if ($type ==  'array' )  
  7.         {  
  8.             $string = "<?php\n return " .var_export($string,TRUE). ";\n?>" ;  
  9.         }  
  10.         elseif($type == 'constant' )  
  11.         {  
  12.             $data='' ;  
  13.             foreach($string as $key => $value) $data .= "define('" .strtoupper($key). "','" .  
  14. addslashes($value)."');\n" ;  
  15.             $string = "<?php\n" .$data. "\n?>" ;  
  16.         }  
  17.     }  
  18.     $strlen = file_put_contents(PHPCMS_CACHEDIR.$file, $string);  
  19.     chmod(PHPCMS_CACHEDIR.$file, 0777 );  
  20.     return  $strlen;  

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics