原文地址:http://52php.com.cn/index.php/archives/6/
总结:
$_REQUEST、$_GET、$_POST、$_COOKIE 的关系和区别。
1.关系:$_REQUEST包含了$_GET、$_POST、$_COOKIE的所有内容,是它们的集合体。
2.$_GET、$_POST、$_COOKIE在$_REQUEST中都有一个副本。改变$_REQUEST的值不影响$_GET等,反之亦然。
3.GET和POST同名的情况下,$_REQUEST取的是POST的值。COOKIE与GET或POST重名的情况下,$_REQUEST取的是COOKIE的值。COOKIE的优先级最高。
测试开始。
测试1:
echo ‘
';//源格式打印
//URL加上m=xxoo来测试$_GET
print_r($_REQUEST);//首先打印内容
print_r($_GET);
$_REQUEST = array();//清空$_REQUEST
echo $_GET['m'];
echo '
‘;
测试结果:$_GET['m']的值是xxoo。
测试2:
echo ‘
';//源格式打印
//URL加上m=xxoo来测试$_GET
print_r($_REQUEST);
print_r($_GET);
$_GET = array();//清空
print_r($_REQUEST);
echo '
‘;
测试结果:$_REQUEST['m']的值是xxoo。
结论:对$_REQUEST的操作没有影响到$_GET,反之亦然。$_REQUEST只是包含了一个$_GET的副本(the same as $_POST 哈哈)。
————————————华丽的分隔线
—————————————————
好。继续
测试3
//POST-GET重名测试
//从其他页面POST传送一个m的值为post,action地址加上m=get
print_r($_REQUEST);
print_r($_GET);
print_r($_POST);
结果:$_REQUEST['m'] == ‘post’。
结论:同时提交GET和POST且同名,$_REQUEST取的是POST的值。(可能是POST优先级更高。)
测试4
//cookie与post\get 重名测试
setcookie(‘m’, ‘cookie’, time()+3600);//先把COOKIE种上,名字为m,值为cookie。然后刷新。(COOKIE要刷新才生效)
//从其他页面POST传送一个m的值为post,action地址加上m=get
print_r($_REQUEST);
结果:$_REQUEST['m'] == ‘cookie’。结论:COOKIE的优先级最高。
将数组类型直接插入MYSQL时插入不进为ARRAY
插入数据前把你的数组序列化:
serialize($list);
读出的时候再使用
unserialize($list);
PHPCMS直接将数组存入数据库的函数。
数组转化为字符串: array2string
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| function array2string($string, $isformdata = 1)
{
if($string == '') return '';
if($isformdata) $string = new_stripslashes($string);
return addslashes(var_export($string, TRUE));
}
function new_stripslashes($string)
{
if(!is_array($string)) return stripslashes($string);
foreach($string as $key => $val) $string[$key] = new_stripslashes($val);
return $string;
} |
stripslashes 函数:
Returns a string with backslashes stripped off. (\’ becomes ‘ and so on.) Double backslashes (\\) are made into a single backslash (\).
该函数用于清理从数据库或 HTML 表单中取回的数据。
删除由 addslashes() 函数添加的反斜杠。
字符串转化为数组:输出。
1
2
3
4
5
6
| function string2array($data)
{
if($data == '') return array();
eval("\$array = $data;");
return $array;
} |
eval
将值代入字符串之中。
语法: void eval(string code_str);
传回值: 无
函式种类: 数据处理
内容说明:
本函式可将字符串之中的变量值代入,通常用在处理数据库的数据上。参数 code_str 为欲处理的字符串。值得注意
的是待处理的字符串要符合 PHP 的字符串格式,同时在结尾处要有分号。使用本函式处理后的字符串会沿续到 PHP
程序结束。
1:使用命令。
备份:
c:\mysql\bin>mysqldump -uroot -h127.0.0.1 -proot 数据库>d:\sql.sql
一条mysqldump语句
mysqldump -u用户名 -h主机地址 -p密码 数据库名>导出的位置:\名称.sql
导入:
mysql>use database name;
Database changed
mysql>source d:\sql.sql;
OK
2:PHPMyadmin
众所周知, PhpMyadmin 是一款很好的可视化mysql管理软件,
选择数据库— 导出–选择SQL 另存为文件; OK
导入的时候同样 import
3:其他
Navicat MysqlFront 等等其他一些mysql可视化软件同样可以备份 还原数据库。
<!-- a { text-decoration:none} #just{border-collapse:collapse;border:solid #6AA70B;border-width:0px 0 0 0px;width:400px; margin:0 auto} #just ul li {padding-top:5px;text-indent:2em;list-style:none;border-bottom:#6AA70B 1px dotted ;font-family: "微软雅黑";font-size: 14px;color:#008000;text-align:left;height:25px;} #just ul li.t1 {background-color:#DEEAFD;} #just ul li.t1 a{color:#000;} #just ul li.t2{background-color:#ffffff;} #just ul li.t2 a{color:#ff0000;} #just ul li.t3 {background-color:#D2FCA0;} -->
<div id="just">
<ul>
<li><a href="http://www.wenan8.com/blog">Just think it</a></li>
<li><a href="http://www.wenan8.com/blog">Just think it</a></li>
<li><a href="http://www.wenan8.com/blog">Just think it</a></li>
<li><a href="http://www.wenan8.com/blog">Just think it</a></li>
<li><a href="http://www.wenan8.com/blog">Just think it</a></li>
<li><a href="http://www.wenan8.com/blog">Just think it</a></li>
<li><a href="http://www.wenan8.com/blog">Just think it</a></li>
<li><a href="http://www.wenan8.com/blog">Just think it</a></li>
<li><a href="http://www.wenan8.com/blog">Just think it</a></li>
</ul>
</div>
<script type="text/javascript">
var Ptr=document.getElementById("generalInfo").getElementsByTagName("li");
function $$() {
for (i=1;i<Ptr.length+1;i++) {
Ptr[i-1].className = (i%2>0)?"t1":"t2";
}
}
window.onload=$$;
for(var i=0;i<Ptr.length;i++) {
Ptr[i].onmouseover=function(){
this.tmpClass=this.className;
this.className = "t3";
};
Ptr[i].onmouseout=function(){
this.className=this.tmpClass;
};
}
</script>
利用jQuery选择器写起来很方便了就。
<script>
$(“#just ul li:even “). css(“color”,”#ff0000″);
</script>
最近公司有个客户需要将几千条的excel表数据导入,给人家导一下吧,以前到也看过一些导入的例子,方法很多,有的转换成csv格式的,txt的,什么都有,但是好多出现乱码情况的,网上PHP读取EXCEL的例子也很多,找了一个很好的类—phpExcelReader ,测试了几次,很不错。 下载地址
下载下后, 更改下 Excel– reader.php 的第31行
require_once 'Spreadsheet/Excel/Reader/OLERead.php';
改为
require_once 'OLERead.ince';
它给的例子的excel我这运行不了, 可能是我装的office的事吧 ^_^。
自己写一个, 现在写一个读取表 插入数据库的实例:
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<?php
require_once 'Excel/reader.php'; //加载所需类
$data = new Spreadsheet_Excel_Reader(); // 实例化
$data->setOutputEncoding('gbk'); //设置编码
$data->read('新建 Microsoft Excel 工作表.xls'); //read函数读取所需EXCEL表,支持中文
$conn= mysql_connect('localhost', 'root', ' ') or die("Can not connect to database."); //连接数据库
mysql_query("set names 'gbk'");//设置编码输出
mysql_select_db('excel'); //选择数据库
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
$sql = "INSERT INTO test VALUES('". $data->sheets[0]['cells'][$i][1]."','". $data->sheets[0]['cells'][$i][2]."','". $data->sheets[0]['cells'][$i][3]."','". $data->sheets[0]['cells'][$i][4]."','". $data->sheets[0]['cells'][$i][5]."','". $data->sheets[0]['cells'][$i][6]."')";
echo $sql.'<br />';
//$insert = mysql_query($sql); 插入部分 注释掉,实际可以自己插入。
}
?>
注意事项
我这的 for $i=2 是从表的第二行开始(一般第一行都得是字段说明,就不插入数据库了。)
注意sheet段
numRows 为你表的行数
cells 表的列数,示例中 插入的是6列的excel表
如果excel是上传的,先上传然后在读取路径 表名,插入数据库。
1.买个闹钟,以便按时叫醒你.
2.如果你不喜欢现在的工作,要么辞职要么闭嘴.
3.学会忍受孤独.
4.走运时做好倒霉的准备.
5.不要像玻璃那样脆弱.
6.管住自己的嘴巴.
7.你失掉了机会,自有别人会得到.
8.若电话老是不响,你该打出去.
9.不要草率结婚.
10.写出一生要做的事,常拿出来看.
好。
转发 | 收藏 | 评论 今天 07:12
工作了2周了,每天9点上班, 6点起床,8点半到公司。6点下班,8点回宿舍,挺规律的生活。第一次上班,什麽都不知道,需要学的还很多哇。
在公司做了1个礼拜的前端,页面仔,学到些没注意过的细节什么的。最近一周开始做程序,接触PHPCMS, 用开源系统做网站, 回头写个小教程,整理下思路。
编码是utf-8
那么js中如果有中文则会输出乱码。
解决方法:
将js保存为 utf-8编码的形式
或者:
<script type="text/javascript" language="javascript" src="scripts/output.js" charset="gb2312"></script>
Recent Comments