当前位置:飞豹网络 → PHP

PHP截取中文的函数

转载请注明出处:http://www.feibao.net

function cnSubstr( $str, $strlen = 16, $suspension_points = 0 )
{
 $j = 0;
    $s = '';
    for ($i = 0; $i < $strlen; $i++) {
        if (ord(substr($str, $i, 2)) > 128) {
            $s .= substr($str, $i, 2);
            $i++;
            $j+=2;
        } else {
            $s .= substr($str, $i, 1);
            $j++;
        }
    }
    if($j%2!=0) $strlen++;
    if (strlen($str)>$strlen && $...

php模拟Cookie

本站原创,转载请注明来源

function getCookieUrl($host_url, $script_name, $method = 'GET', $data = '', $cookie_str = '')
{
    $sock = fsockopen($host_url, 80, $errno, $errstr, 30);
    if (!$sock) die("$errstr ($errno)\n");
    $method = strToUpper($method);
    $method = ($method == 'GET') ? 'GET' : 'POST';
    if (substr($script_name, 0, 1) != '/') {
        $script_name = '/' . $script_name;
    }

    fwrite($sock, $method . " " . $script_name . " HTTP/1.0\r\n");
    fwrite($sock, "Host: " . $host_url . "\r\n");
    if (!empty($cookie_str)) {
        fwrite($sock, "COOKIE: " . $cookie_str . "\r\n");
    }
    fwri...

PHP优化的点击数统计代码

本站原创,转载请注明来源

error_reporting(E_ALL);
$ROOT_PATH = '../';
include_once($ROOT_PATH . "include/config.php");

$update_time = 1800;//多长时间更新一次,单位是秒

$article_id = (isset($_GET['article_id']) && is_numeric($_GET['article_id']) && $_GET['article_id'] > 0) ? intval($_GET['article_id']) : 0;//文章的ID
if ($article_id > 0) {

    $filename = $ROOT_PATH . 'log/click_log.txt';
    $s = '';
    if (file_exists($filename)) {
        $content = file_get_contents($filename);
        $d_ary = array();
        if ($content) {
            $ary = explode("\n", $content);
            foreach ($ary as $line) {
           ...

PHP代码规范化

转载请注明来源

1.TAB键,相当于4个空格,而不是真实的TAB,可以在编辑器软件中设置(可省略)
2.代码格式:例子:(if, for, while, switch等等)
if ((condition1) || (condition2)) {
    action1;
} elseif ((condition3) && (condition4)) {
    action2;
} else {
    defaultaction;
}

switch (condition) {
    case 1:
        action1;
        break;

    case 2:
        action2;
        break;

    default:
        defaultaction;
        break;

}
if 与后面的小括号,有一个空格,后面的那个小括号与括号里面的代码第一个字母之间,没有空格, ||, && 等数学符号左右,要有空格
右括号与综...

常用的adodb使用方法,学习资料

本文原创,转载请注明来源: http://www.feibao.net

 

/*
常用的ADODB使用方法
整理:飞豹游侠 QQ:8527385 E-mail:liuchengcn # 163.com
如有错误之处,敬请谅解,并QQ或E-mail通知我,谢谢
*/
//定义数据库变量
$DB_TYPE     = "mysql";
$DB_HOST     = "localhost";
$DB_USER     = "root";
$DB_PASS     = "";
$DB_DATABASE = "ai-part";
require_once("../adodb/adodb.inc.php");
$db = NewADOConnection("$DB_TYPE");//建立数据库对象
$db->debug = true;//数据库的DEBUG测试,程序开发期,可设置为true,正式版要注释掉这行,(默认值是false)
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
/*
返回的记录集形式
define('ADODB_FETCH_DEFAULT',0);
define('ADODB_FETCH_NUM',1);
define('ADODB_FETCH_ASSOC',2)...