php数组保存文本与文本反编成数组实例_PHP

WBOY
Release: 2016-05-31 19:27:53
Original
704 people have browsed it

本文实例讲述了php数组保存文本与文本反编成数组的方法。分享给大家供大家参考。具体实现方法如下:

下面的实例定义了两个函数,其中string2array用于将字符串转换成数组,array2string用于将数组转换成字符串。

具体实现代码如下:

代码如下:

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

希望本文所述对大家的PHP程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template