这篇文章主要介绍了php数组保存文本与文本反编成数组的方法,通过两个自定义函数string2array与array2string实例展示了php数组保存文本与文本反编成数组的实现方
本文实例讲述了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程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
