• PHP eval() 函数


    eval() 函数把字符串按照 PHP 代码来计算。

    该字符串必须是合法的 PHP 代码,且必须以分号结尾。

    如果没有在代码字符串中调用 return 语句,则返回 NULL。如果代码中存在解析错误,则 eval() 函数返回 false

    <?php
    $string = "beautiful";
    $time = "winter";
    
    $str = 'This is a $string $time morning!';
    echo $str. "<br />";
    
    eval("$str = "$str";");
    echo $str;
    ?> 
    
    	/**
    	 * 得到数组变量的GBK编码
    	 *
    	 * @param array $key 数组
    	 * @return array 数组类型的返回结果
    	 */
    	public static function getGBK($key){
    		/**
    		 * 转码
    		 */
    		if (strtoupper(CHARSET) == 'GBK' && !empty($key)){
    			if (is_array($key)){
    				$result = var_export($key, true);//变为字符串
    				$result = iconv('UTF-8','GBK',$result);
    				eval("$result = $result;");//转换回数组
    			}else {
    				$result = iconv('UTF-8','GBK',$key);
    			}
    		}
    		return $result;
    	}
    
  • 相关阅读:
    数据库设计范式
    SQL 触发器
    SQL查询上月和本月两个月的语句
    angularjs学习总结 详细教程
    指令
    重复 HTML 元素
    AngularJS 数据绑定
    AngularJS 指令.
    AngularJS 数组
    AngularJS 对象
  • 原文地址:https://www.cnblogs.com/Alight/p/4345831.html
Copyright © 2020-2023  润新知