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

yipeiwu_com5年前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编程注意事项的小结

 1、php隐性的三元操作符(?:)优先级问题: 例1:复制代码 代码如下:    $person = $who or $person = "la...

php UTF-8、Unicode和BOM问题

php UTF-8、Unicode和BOM问题

一、介绍 UTF-8 是一种在web应用中经常使用的一种 Unicode 字符的编码方式,使用 UTF-8 的好处在于它是一种变长的编码方式,对于 ANSII 码编码长度为1个字节,这样...

asp函数split()对应php函数explode()

<?php //利用 explode 函数分割字符串到数组 $source = "hello1,hello2,hello3,hello4,hello5";//按逗号分离...

php解决和避免form表单重复提交的几种方法

前言 为什么要避免form表单被重复提交呢?因为我们不想让我们的服务器重复处理没必要的数据,同时我们也是避免我们的数据库产生重复的数据,避免表单重复提交也是让我们的网站更安全的一种表现。...

PHPExcel在linux环境下导出报500错误的解决方法

原先我导出为 XLSX 格式,用的是 $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel2007'); 报错,纠...