PHP/MySQL

rand() 生成32位随机码(code)

Posted on 八月 23rd, 2010 by keeperhan and tagged .
keeperhan 的头像

       rand() 返回 0 到 RAND_MAX 之间的伪随机整数 , 比如你想要 10 到 20(包括 10 和 120)之间的随机数,用 rand(10, 20) 即可 . 如下是利用 rand()函数生成一个32位随机码(code) , 其中还利用到了shuffle()函数 ; shuffle()函数是将数组打乱(随机排列单元的顺序) . 要注意的是shuffle()函数为 array 中的单元赋予新的键名。这不仅是重新排序而且将删除原有的键名。
    $code = "";
    $chars = array(

Articles tagged with: for column ’storage_pid’ at row 1′错误

Posted on 八月 6th, 2010 by lichangyu and tagged .
lichangyu 的头像

Articles tagged with: for column ’storage_pid’ at row 1′
Typo3 Issuses »
Typo3: SQL error: ‘Incorrect integer value: ” for column ’storage_pid’ at row 1′
[5 Dec 2009 | No Comment | 8,782 Views]
为了方便调试Typo3程序,所以选择了在本地安装和使用Typo3网站程序,所有安装都完成了,当我开始创建第一个页面时,保存出现错误提示:

array_unshift()在数组开头插入一个或多个单元

Posted on 六月 5th, 2010 by keeperhan and tagged .
keeperhan 的头像

       array_unshift — 在数组开头插入一个或多个单元 . 注意单元是作为整体被插入的,因此传入单元将保持同样的顺序。所有的数值键名将修改为从零开始重新计数,所有的文字键名保持不变。
<?php
$queue = array("orange", "banana");
array_unshift($queue, "apple", "raspberry");
?>

这将使 $queue 包含如下单元:
Array
(

array_unique() 移除数组中重复的值

Posted on 六月 5th, 2010 by keeperhan and tagged .
keeperhan 的头像

       array_unique() — 移除数组中重复的值 .  注意键名保留不变。array_unique() 先将值作为字符串排序,然后对每个值只保留第一个遇到的键名,接着忽略所有后面的键名。这并不意味着在未排序的 array 中同一个值的第一个出现的键名会被保留。 注意: 当且仅当 (string) $elem1 === (string) $elem2 时两个单元被认为相同。就是说,当字符串的表达一样时。 第一个单元将被保留。
<?php

MYSQL 百万级数据 提取部分字段 生成文件/生成时间毫秒级

Posted on 五月 31st, 2010 by lichangyu and tagged .
lichangyu 的头像

1.MYSQL百万级数据提取部分字段生成文件/生成时间毫秒级。

2.into outfile ...

3.FIELDS TERMINATED BY ',':分隔符,可选项

4.select id,u_id into outfile 'rid_uid.txt' FIELDS TERMINATED BY ',' from role;

5.从role表中查询出id,u_id 以','分隔两个字段 生成 rid_uid.txt文件,生成的路径默认到mysql/data/数据库名/rid_uid.txt

php5.3 几个新添功能

Posted on 五月 18th, 2010 by cfanwzl and tagged .
cfanwzl 的头像

          php5.3也发布好久了,用到了几个函数,发到这里,一起学习下.
_callStatic() magic 方法

php 正则表达式 匹配 中国移动手机号码

Posted on 五月 7th, 2010 by keeperhan and tagged .
keeperhan 的头像

        提供一个使用正则表达式匹配中国移动手机号码的例子, 2010年最新.
<?php
$str = "15866548083";
$rs = preg_match('/^(13[4-9]|15[0|1|2|7|8|9]|18[7|8]|147)\d{8}$/',$str);
if($rs) {
    echo "chinamobile";
}else{
    echo "error";
}
?>

php有用的函数(一)

Posted on 五月 6th, 2010 by cfanwzl and tagged .
cfanwzl 的头像

// 两个默认参数的函数
function test($arg1 = '', $arg2 = '') {
    echo "arg1: $arg1 <br />";
    echo "arg2: $arg2 <br />";
}
test('hello','world');
/* 输出:
arg1: hello
arg2: world
*/
test();
/* 输出:
arg1:
arg2:
*/
func_get_args()//
//  任意个数的参数
function test() {
    // 取得所有的传入参数的数组
    $all_args = func_get_args();

array_merge() 数组单元合并

Posted on 四月 21st, 2010 by keeperhan and tagged .
keeperhan 的头像

       array_merge() 将一个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面。返回作为结果的数组。 如果输入的数组中有相同的字符串键名,则该键名后面的值将覆盖前一个值。然而,如果数组包含数字键名,后面的值将不会覆盖原来的值,而是附加到后面。 如果只给了一个数组并且该数组是数字索引的,则键名会以连续方式重新索引。
array_merge() 例子:
<?php
$array1 = array("color" => "red", 2, 4);

php 上传图片可按比例生成缩略图

Posted on 四月 20th, 2010 by cfanwzl and tagged .
cfanwzl 的头像

        如下是一个功能比较齐全的php图片上传类,
        主要功能:
            1.可按比例生成缩略图
            2.可设置水印的位置
            3.可生成一个可能失真的略缩图.
        下面是其中的一个函数,如若查看或是使用可下载该文件类.