PHP中使用SPLIT()时出现Warning: split(): REG_EMPTY错误的解决办法: 很有可能是由于使用了“|”做分隔符,像这样:
$Arr = split('|',$string);
此时需要对“|”进行转义,这样使用“|”:
$Arr = split('|',$string);
就可以了。
阅读全文

PHP中使用SPLIT()时出现Warning: split(): REG_EMPTY错误的解决办法: 很有可能是由于使用了“|”做分隔符,像这样:
$Arr = split('|',$string);
此时需要对“|”进行转义,这样使用“|”:
$Arr = split('|',$string);
就可以了。
安装 Apache2:
sudo apt-get install apache2
安装PHP模块:
sudo apt-get install php5
编辑测试页:
sudo vim/var/www/index.php
如果提示还没有安装vim,可以用以下bash安装
sudo apt-get install vim
#!/bin/bash
fdate=20111001
while [ $fdate != "20111021" ]
do
#echo $fdate;
perl -e "print $fdate;"#使用perl脚本处理文件
fdate=$(($fdate+1));
done
这是我第一次写shell脚本,虽然很简单哈,,不过确实是我为了工作需求而写出来的一个脚本,可以顺序执行20条perl命令,去处理20天的数据,每天的数据处理都得可能要花上一个小时,所以如果人为的去一条一条处理的话,太浪费时间了,写个perl、php或者Python脚本倒是也很简单,不过最近正好在看bash的书,正好当作实践一下了。
APR_DECLARE_NONSTD(unsigned int) apr_hashfunc_default(const char *char_key,
apr_ssize_t *klen)
{
unsigned int hash = 0;
const unsigned char *key = (const unsigned char *)char_key;
const unsigned char *p;
apr_ssize_t i;
/*
* This is the popular `times 33' hash algorithm which is used by
* perl and also appears in Berkeley DB. This is one of the best
* known hash functions for strings because it is both computed
* very fast and distributes very well.
*
* The originator may be Dan Bernstein but the code in Berkeley DB
* cites Chris Torek as the source. The best citation I have found
* is "Chris Torek, Hash function for text in C, Usenet message
* <27038@mimsy.umd.edu> in comp.lang.c , October, 1990." in Rich
* Salz's USENIX 1992 paper about INN which can be found at
* .
*
* The magic of number 33, i.e. why it works better than many other
* constants, prime or not, has never been adequately explained by
* anyone. So I try an explanation: if one experimentally tests all
* multipliers between 1 and 256 (as I did while writing a low-level
* data structure library some time ago) one detects that even
* numbers are not useable at all. The remaining 128 odd numbers
* (except for the number 1) work more or less all equally well.
* They all distribute in an acceptable way and this way fill a hash
* table with an average percent of approx. 86%.
*
* If one compares the chi^2 values of the variants (see
* Bob Jenkins ``Hashing Frequently Asked Questions'' at
* http://burtleburtle.net/bob/hash/hashfaq.html for a description
* of chi^2), the number 33 not even has the best value. But the
* number 33 and a few other equally good numbers like 17, 31, 63,
* 127 and 129 have nevertheless a great advantage to the remaining
* numbers in the large set of possible multipliers: their multiply
* operation can be replaced by a faster operation based on just one
* shift plus either a single addition or subtraction operation. And
* because a hash function has to both distribute good _and_ has to
* be very fast to compute, those few numbers should be preferred.
*
* -- Ralf S. Engelschall
*/
if (*klen == APR_HASH_KEY_STRING) {
for (p = key; *p; p++) {
hash = hash * 33 + *p;
}
*klen = p - key;
}
else {
for (p = key, i = *klen; i; i--, p++) {
hash = hash * 33 + *p;
}
}
return hash;
}
哈希表和哈希函数是大学数据结构中的课程,实际开发中我们经常用到Hashtable这种结构,当遇到键-值对存储,采用Hashtable比ArrayList查找的性能高。为什么呢?我们在享受高性能的同时,需要付出什么代价(这几天看红顶商人胡雪岩,经典台词:在你享受这之前,必须受别人吃不了的苦,忍受别人受不了的屈辱),那么使用Hashtable是否就是一桩无本万利的买卖呢?就此疑问,做以下分析,希望能抛砖引玉。
阅读全文
Select在Socket编程中还是比较重要的,可是对于初学Socket的人来说都不太爱用Select写程序,他们只是习惯写诸如connect、accept、recv或recvfrom这样的阻塞程序(所谓阻塞方式block,顾名思义,就是进程或是线程执行到这些函数时必须等待某个事件的发生,如果事件没有发生,进程或线程就被阻塞,函数不能立即返回)。可是使用Select就可以完成非阻塞(所谓非阻塞方式non-block,就是进程或线程执行此函数时不必非要等待事件的发生,一旦执行肯定返回,以返回值的不同来反映函数的执行情况,如果事件发生则与阻塞方式相同,若事件没有发生则返回一个代码来告知事件未发生,而进程或线程继续执行,所以效率较高)方式工作的程序,它能够监视我们需要监视的文件描述符的变化情况——读写或是异常。下面详细介绍一下!
Select的函数格式(我所说的是Unix系统下的伯克利socket编程,和windows下的有区别,一会儿说明):
int select(int maxfdp,fd_set *readfds,fd_set *writefds,fd_set *errorfds,struct timeval *timeout);
先说明两个结构体:
第一,struct fd_set可以理解为一个集合,这个集合中存放的是文件描述符(file descriptor),即文件句柄,这可以是我们所说的普通意义的文件,当然Unix下任何设备、管道、FIFO等都是文件形式,全部包括在内,所以毫无疑问一个socket就是一个文件,socket句柄就是一个文件描述符。fd_set集合可以通过一些宏由人为来操作,比如清空集合FD_ZERO(fd_set *),将一个给定的文件描述符加入集合之中FD_SET(int ,fd_set *),将一个给定的文件描述符从集合中删除FD_CLR(int ,fd_set*),检查集合中指定的文件描述符是否可以读写FD_ISSET(int ,fd_set* )。一会儿举例说明。
第二,struct timeval是一个大家常用的结构,用来代表时间值,有两个成员,一个是秒数,另一个是毫秒数。
今天,在使用notepad++新制作一个程序时,总是提示警告,并且session不起作用。
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:FukunPhpwap_cailingmodify.php:1) in E:fPhpwap_cailingchklogin.php on line 2Warning: Cannot modify header information - headers already sent by (output started at E:fPhpwap_cailingmodify.php:1) in E:FukunPhpwap_cailingmodify.php on line 4
经检查后发现是由于PHP中的UTF-8格式的BOM引起的。
解决办法就是删除掉BOM,例如使用notepad++时,可以使用以下方式解决。
