Posts Tagged ‘Dips’

Dips4:关于整型integer遇到的进制和溢出的问题

October 12th, 2008
$v = 04555720201;
echo $v;

恩。。。。输出结果是632791169

起初以为是溢出的,最后发现是因为以0开头的整型会被认为八进制。

查了点资料做备份。
1.Syntax:
Integers can be specified in decimal (base 10), hexadecimal (base 16), or octal (base 8) notation, optionally preceded by a sign (- or +).

To use octal notation, precede the number with a 0 (zero). To use hexadecimal notation precede the number with 0x.

decimal : [1-9][0-9]*
| 0

hexadecimal : 0[xX][0-9a-fA-F]+

octal : 0[0-7]+

integer : [+-]?decimal
| [+-]?hexadecimal
| [+-]?octal

2.溢出overflow

If PHP encounters a number beyond the bounds of the integer type, it will be interpreted as a float instead. Also, an operation which results in a number beyond the bounds of the integer type will return a float instead.

32位系统是2^32-1(?)

注:Mysql里的有符号整型是-2147483648 到2147483647(与PHP相同),无符号的是0 到4294967295

2010.01.08更新3. cookie不能设置为100年哇,虽然想做永久不过期,但是不必须设100年哇,100年会导致PHP溢出的。。。。

  • Share/Save/Bookmark

Dips3:preg_replace可使用 /e 修正符将replacement参数当作PHP代码来执行

September 2nd, 2008

preg_replace可使用 /e 修正符将 replacement 参数当作 PHP 代码来执行(在适当的逆向引用替换完之后)。
(Read More)

  • Share/Save/Bookmark

Dips2:GBK->UTF-8项目转码过程中需要注意的问题

August 28th, 2008

1.UTF-8分BOM和No BOM两种(某记事本++可以转换)
PS: 有BOM会引起COOKIE操作报错
PPS: 据不完全统计,notepad另存为的是有BOM的,Editplus另存为的是No BOM的

2.CSS没转换成UTF-8的话会在IE6显示不了,其他浏览器似乎不受影响

  • Share/Save/Bookmark

Dips1:JS中获得PHP json_encode后的数据处理

August 22nd, 2008

一个通过AJAX来实现二级联动的东西,PHP获取数组以json的形式返回给JS
这里有个小地方需要注意,PHP中json_encode函数return的结果是string的形式
所以传到JS后还需要通过eval()函数来以JS代码形式执行这段string

PS:与JS交互还是JSON比XML方便吖XD

function setbaby(classid,babyid){
	var class_id = document.getElementById(classid).value;
	var x = new Ajax('statusid', 'HTML');
	x.get('batch.common.php?action=getbaby&classid='+class_id, function(s){
		var babyOptions = new Array();
		var babyOptions = eval(s);
		var babyObject = document.getElementById(babyid);
		babyObject.options.length = 0;
		babyObject.options[0] = new Option("选择宝宝","");
		var j=0;
		for(var i=0;i
  • Share/Save/Bookmark