Home > Backend Development > PHP Tutorial > 页面内数组传值解决思路

页面内数组传值解决思路

WBOY
Release: 2016-06-13 10:17:36
Original
878 people have browsed it

页面内数组传值
a.php中有一个二维数据,传给b.php
a.php

HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Copy after login
//此处如处写啊??有何技巧???

b.php
if($_GET['m']){
print_r($_POST['data']);
saveData($_POST['data']);//一个插入数据库函数
}
?>
通过此法,得到的$_POST['data']变成了一个三维数组了,如何办???

------解决方案--------------------
序列化

serialize

需要注意转义问题
------解决方案--------------------
探讨

引用:

好汉,我不懂,请你再明确一下

------解决方案--------------------


把序列化的值传到隐藏域中,传给b.php去处理 ,b.php那边,unserialize($_POST['data'])//出来就是一个数组,

serialize() 返回字符串 ,具体查下手册
------解决方案--------------------
if($_GET['m']){
print_r(unserialize($_POST['data']));//这只是验证一下数据的完整性
saveData(unserialize($_POST['data']));//这样才能传递数组过去
}

------解决方案--------------------


序列化需要addslashes转义

传值的时候,通常默认,或程序统一addslashes

,看效果用,服务端根据需要去掉几重转义
PHP code
$arr    = array("'", "\\");print_r(unserialize(stripslashes(stripslashes(addslashes(addslashes(serialize($arr)))))));<div class="clear">
                 
              
              
        
            </div>
Copy after login
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