php中将数组转成字符串并保存到数据库中的函数代码

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

/**
* 将字符串转换为数组
*
* @param    string  $data   字符串
* @return   array   返回数组格式,如果,data为空,则返回空数组
*/ 
 function string2array($data) {  
    if($data == '') return array();  
    @eval("\$array = $data;");  
    return $array;  
}  
 /**
* 将数组转换为字符串
*
* @param    array   $data       数组
* @param    bool    $isformdata 如果为0,则不使用new_stripslashes处理,可选参数,默认为1
* @return   string  返回字符串,如果,data为空,则返回空
*/ 
function array2string($data, $isformdata = 1) {  
    if($data == '') return '';  
    if($isformdata) $data = new_stripslashes($data);  
    return addslashes(var_export($data, TRUE));  

相关文章

php URL验证正则表达式

复制代码 代码如下: <?php $url = 'http://www.baidu.com/zongzi/oo.html'; $n = preg_match_all("/http:...

PHP-CGI进程CPU 100% 与 file_get_contents 函数的关系分析

后来,我通过跟踪发现,这类情况的出现,跟 PHP 的 file_get_contents() 函数有着密切的关系。   大、中型网站中,基于 HTTP 协议的 API 接口调用,是家常便...

php把数组值转换成键的方法

本文实例讲述了php把数组值转换成键的方法。分享给大家供大家参考。具体如下: function values2keys($arr, $value=1){ $new = array...

PHP中ltrim()函数的用法与实例讲解

PHP中ltrim()函数的用法与实例讲解

PHP ltrim() 函数 实例 移除字符串左侧的字符: <?php $str = "Hello World!"; echo $str . "<br>...

Discuz5.5.0代码高亮显示+运行代码框合成插件 下载第1/4页

主要功能: 1.几乎支持所有程序代码的高亮显示,包括以下语言:Actionscript、ADA、Apache Log、AppleScript、ASM、ASP、AutoIT、Ba...