I'm twiting

访问统计

free counters

PHP & svn 经验总结(长期更新)

safe_mode必须设为off,on状态导致许多内置文件系统函数不能正常工作,php官方不赞成启用本函数。
php扩展的编译。在linux下给php加扩展不需要重新编译php,可以编译成so文件,由php加载该目录即可。
windows安装apache+php时,要需要在extension_dir指定扩展文件的目录,高版本得php(当前是PHP 5.3.2),默认得扩展目录时c:\php5,旧版本只要在系统path设定一下就可以了。
zend optimizer 3.3.3版不支持php5.3,兄弟们不用试了。。。
svn 中文件名不要用大小写来区分,在linux下可能没问题,但在win下会报系统找不到指定的文件这个错误。
PDT打开代码自动提示。打开 Eclipse的 Window -> Preferences -> PHP -> Editor ->Code Assist->Auto Activation打开里面的Enable auto activation选项。

php求数组并集的函数

/**

 * 求多个数组的并集

 */

function array_union()

{

    $argsCount = func_num_args();

 

    if ($argsCount < 2)

    {

        return false;

    }

    else if (2 == $argsCount)

    {

     list($arr1, $arr2) = func_get_args();

 

     while (list($k, $v) = each($arr2))

     {

         if (!in_array($v, $arr1)) $arr1[] = $v;

     }

 

     return [...]

file_get_contents和\n的那些事

用file_get_contents去获取一段url的内容,结果总是显示404,实际上页面是存在的。搞了半天不明白,后来发现报错的url后带一个空白,猜想可能是url后面多了\n的话file_get_contents就会报错,就在url上加了个trim,马上就成功了!!-_-这file_get_contents的容错性真是……

PHP 版的 Curl 使用代理服务器示例

Curl 可以模拟浏览器访问url地址,但是有些网站我们无法直接访问,所以需要使用代理。上PHP 手册查一下对使用 sockets5 只是笼统的介绍了一下,这里贴出 PHP 版的 Curl 使用 sockets5 代理的示例代码,以便日后查阅。

< ?php

$remote_url = 'http://www.google.com';

$ch = curl_init($remote_url);      

curl_setopt($ch, CURLOPT_HEADER, 0);

 

//以下代码设置代理服务器

//是否启用代理

curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);

//代理认证模式

curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);

//代理服务器地址

curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1");

//代理服务器端口

curl_setopt($ch, CURLOPT_PROXYPORT, 8866);

//代理模式,这里用socket5的方式

curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);

 

 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$res = curl_exec($ch); // Run it!

curl_close($ch); //关闭curl通道

echo $res;

转自PHP手册:比较substr, mb_substr和mb_strcut

I found this function to be extremely useful.
Here is a practical example, showing the difference between substr(), mb_substr() and mb_strcut():
<?php
mb_internal_encoding(‘UTF-8′);
$string = ‘cioèòà’;
var_dump(
substr($string, 0, 6),
mb_substr($string, 0, 6),
mb_strcut($string, 0, 6)
);
?>

Output:
string(6) “cioè?”
string(9) “cioèòà”
string(5) “cioè”
Explanation:
$string is long 9 bytes
c - 1 byte
i - 1 byte
o - 1 byte
è - 2 bytes
ò - 2 bytes
à - 2 bytes
substr() works with [...]

我的第一个框架

下载
虚拟主机配置
ServerName paydev.taomee.com
ServerAdmin symphony@taomee.com
DocumentRoot “/var/www/paydev”
Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !.*(\.css|\.js|\.html|\.zf|\.gif|\.pdf|\.rar|\.ppt|\.chm|\.png|\.jpg|\.jpeg)$
RewriteRule ^(.*)$ index.php [QSA,L]
ErrorLog “/var/log/apache2/paydev_errors.log”
CustomLog “/var/log/apache2/paydev_accesses.log” common

获取参数信息:func_num_args和func_get_args

Examples

Example #1 func_get_args() example

function foo()
{
$numargs = func_num_args();
echo “Number of arguments: $numargs\n”;
if ($numargs >= 2) {
echo “Second argument is: ” . func_get_arg(1) . “\n”;
}
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo “Argument $i is: ” . $arg_list[$i] . “\n”;
}
}
foo(1, 2, 3);
?>

The above example will output:

Number of arguments: 3

Second argument is: 2

Argument 0 is: 1

Argument 1 is: 2

Argument 2 is: 3

PHP 获取当前类名、方法名

__CLASS__ 获取当前类名(在此之前我用get_class - -!)
__FUNCTION__ 当前函数名(confirm)
__METHOD__ 当前方法名 (bankcard::confirm)

非常好用!