js检测网址中是否存在get参数

var ntype = isNtype();
//检测是否存在ntype参数
function isNtype(){
    var url = document.location.href;
    if(url.indexOf('ntype') > 0){
        return 1;
    }else{
        return 0;
    }
}

如何将系统的data目录迁移到web以外目录

data目录是系统缓存和配置文件的目录,一般都有可以读写的权限,只要是能够写入的目录都可能存在安全隐患,很多站长甚至给予这个目录可执行的权限,更是非常危险,所以我们建议将这个data目录搬移出Web可访问目录之外。本篇将介绍如何将data目录搬移出Web访问目录。

- 阅读剩余部分 -

命名空间namespace的简单介绍

//php文件中引用同名类会产生错误,命名空间即可解决此类问题。
//a.class.php

class Apple{
    public function get_info(){
        echo "this is a.class";
    }
}

//b.class.php

class Apple{
    public function get_info(){
        echo "this is b.clss";
    }
}

//index.php
require_once "a.class.php";
require_once "b.class.php";
//这样直接引用必然会产生致命错误,由此引入命名空间
//在a.class.php顶部添加 namespace a\b\c b.class.php添加 namespace d\e\f
//此时同时引入不会再出错
$a = new a\b\c\Apple();
$a->get_info();
//同理获取b.class
// 为了便于重复使用,直接使用
use a\b\c\Apple;
$a = new Apple();

// 同样在使用b.class时,可以使用as
use d\e\f\Apple as bApple;

//如果存在一个c.class.php存在与底层,即为为设置命名空间
// c.class.php

class Apple{
    public function get_info(){
        echo "this is c.clss";
    }
}

//则此时调用该类则需要在其前面添加\来判定为底层类
$c = new \Apple();

php获取本地ip地址,局域网ip获取

<?php
header("Content-type: text/html; charset=gb2312");

function getLocalIP(){
    exec("ipconfig /all", $output);

    foreach($output as $line){
        if (preg_match("/(.*)IPv4(.*)/", $line)){
            $ip = $line;
            $ip = str_replace("IPv4 地址 . . . . . . . . . . . . :","",$ip);
            $ip = str_replace("(首选)","",$ip);
        }
    }
    return $ip;
}
echo $ip = getLocalIP();

在程序使用时由于使用utf-8,而默认系统为gbk,则考虑使用正则匹配来判断:

if (preg_match("/(.*)IPv4(.*)/", $line)){
     $ip = preg_replace('/.*:/', '', $line);
     $ip = preg_replace('/[^\d^\.]/', '', $ip);
}

使用phpQuery轻松采集网页内容

我们有时需要抓取一个网页的内容,但只需要特定部分的信息,通常会用正则来解决,这当然没有问题。正则是一个通用解决方案,但特定情况下,往往有更简单快 捷的方法。比如你想查询一个编程方面的问题,当然可以使用Google,但stackoverflow 作为一个专业的编程问答社区,会提供给你更多,更靠谱的答案。

- 阅读剩余部分 -

wget 递归下载整个网站(网站扒皮必备)

wget这个命令可以以递归的方式下载整站,并可以将下载的页面中的链接转换为本地链接。wget加上参数之后,即可成为相当强大的下载工具。

wget命令详解
wget -r -p -np -k http://xxx.com/xxx
-r, --recursive(递归) specify recursive download.(指定递归下载)
-k, --convert-links(转换链接) make links in downloaded HTML point to local files.(将下载的HTML页面中的链接转换为相对链接即本地链接)
-p, --page-requisites(页面必需元素) get all images, etc. needed to display HTML page.(下载所有的图片等页面显示所需的内容)
-np, --no-parent(不追溯至父级) don't ascend to the parent directory.
另外断点续传用-nc参数 日志 用-o参数