常用的PHP采集

//取图片
preg_match_all('/<div class=\"conlist\">(.*?)<div class="ft">/is',$content,$imgcontent);
$content=$imgcontent[0][0];
preg_match_all('/<div class=\"pic\"\>(.*?)<\/div\>/is',$content,$imgcontent);
$imgcontent=$imgcontent[0];
if($imgcontent){
	$i=0;
    foreach($imgcontent as $value){	
		preg_match('/<img src=\"(.*?)\" alt=/is',$value,$imghref);
		$product[$i][img]=$imghref[1];
	    $i++;
	}
}

//取产品介绍
preg_match_all('/<br clear=\"all\"\/>(.*?)<a href=\"/is',$content,$infocontent);
$infocontent=$infocontent[1];
if($infocontent){
	$i=0;
    foreach($infocontent as $value){
		$product[$i][info]=trim($value);
	    $i++;
	}
}

//取产品名称
preg_match_all('/class=\"title\" id=\"proName_(.*?)\">(.*?)<\/a>/is',$content,$namecontent);
$infocontent=$namecontent[2];
if($infocontent){
	$i=0;
    foreach($infocontent as $value){
		$product[$i][name]=trim($value);
	    $i++;
	}
}

//取产品价格
preg_match_all('/<span class=\"price\">(.*?)<\/span>/is',$content,$pricecontent);
$pricecontent=$pricecontent[1];
//print_r($pricecontent);
if($pricecontent){
	$i=0;
    foreach($pricecontent as $value){
		preg_match('/<b >(.*?)<\/b>/is',$value,$imgpai);
		$product[$i][price]=$imgpai[1];
	    $i++;
	}
}

 

ECshop前台分页

代码如下:

---------------------------------------在要分页的sql上面加上如下代码 ----------------------------------------------------

$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
$record_count = $db->getOne('总数的sql语句');
//例如 $record_count = $db->getOne('select count(*) from '.$ecs->table('goods'));
$pager = get_pager('php页面', php页面的参数 , $record_count, $page,每页显示几个,分页样式);
//例如 $pager = get_pager('test.php', array('act' => $_REQUEST['act'],'id' => $_REQUEST['id']), $record_count, $page,5,0);
$smarty->assign('pager', $pager);

//分页的sql语句

$sql= 分页sql语句.' LIMIT '.$pager['start'].','.$pager['size'];

//例如 $sql= 'select count(*) from '.$ecs->table('goods').' LIMIT '.$pager['start'].','.$pager['size'];

------------------------------------------------------------------get_pager 方法----------------------------------------------

function get_pager($url, $param, $record_count, $page = 1, $size = 10, $styleid=1)
{
    $size = intval($size);
    if ($size < 1)
    {
        $size = 10;
    }

    $page = intval($page);
    if ($page < 1)
    {
        $page = 1;
    }

    $record_count = intval($record_count);

    $page_count = $record_count > 0 ? intval(ceil($record_count / $size)) : 1;
    if ($page > $page_count)
    {
        $page = $page_count;
    }
    /* 分页样式 */
    $pager['styleid'] = $styleid;

    $page_prev = ($page > 1) ? $page - 1 : 1;
    $page_next = ($page < $page_count) ? $page + 1 : $page_count;

    /* 将参数合成url字串 */
    $param_url = '?';
    foreach ($param AS $key => $value)
    {
        $param_url .= $key . '=' . $value . '&';
    }

    $pager['url']          = $url;
    $pager['start']        = ($page -1) * $size;
    $pager['page']         = $page;
    $pager['size']         = $size;
    $pager['record_count'] = $record_count;
    $pager['page_count']   = $page_count;

    if ($pager['styleid'] == 0)
    {
        $pager['page_first']   = $url . $param_url . 'page=1';
        $pager['page_prev']    = $url . $param_url . 'page=' . $page_prev;
        $pager['page_next']    = $url . $param_url . 'page=' . $page_next;
        $pager['page_last']    = $url . $param_url . 'page=' . $page_count;
        $pager['array'] = array();
        for ($i = 1; $i <= $page_count; $i++)
        {
            $pager['array'][$i] = $i;
        }
    }
    else
    {
        $_pagenum = 10;     // 显示的页码
        $_offset = 2;       // 当前页偏移值
        $_from = $_to = 0; // 开始页, 结束页
        if($_pagenum > $page_count)
        {
            $_from = 1;
            $_to = $page_count;
        }
        else
        {
            $_from = $page - $_offset;
            $_to = $_from + $_pagenum - 1;
            if($_from < 1)
            {
                $_to = $page + 1 - $_from;
                $_from = 1;
                if($_to - $_from < $_pagenum)
                {
                    $_to = $_pagenum;
                }
            }
            elseif($_to > $page_count)
            {
                $_from = $page_count - $_pagenum + 1;
                $_to = $page_count;
            }
        }
        $url_format = $url . $param_url . 'page=';
        $pager['page_first'] = ($page - $_offset > 1 && $_pagenum < $page_count) ? $url_format . 1 : '';
        $pager['page_prev'] = ($page > 1) ? $url_format . $page_prev : '';
        $pager['page_next'] = ($page < $page_count) ? $url_format . $page_next : '';
        $pager['page_last'] = ($_to < $page_count) ? $url_format . $page_count : '';
        $pager['page_kbd'] = ($_pagenum < $page_count) ? true : false;
        $pager['page_number'] = array();
        for ($i=$_from;$i<=$_to;++$i)
        {
            $pager['page_number'][$i] = $url_format . $i;
        }
    }
    $pager['search'] = $param;

    return $pager;
}

------------------------------------------------------ html 分页代码 ---------------------------------------------------------

<!--翻页 start-->
<form name="selectPageForm" action="{$smarty.server.PHP_SELF}" method="get">
<!-- {if $pager.styleid eq 0 } -->
<div id="pager">
总计{$pager.record_count}个记录,共{$pager.page_count} 页。 <span> <a href="{$pager.page_first}">{$lang.page_first}</a> <a href="{$pager.page_prev}">{$lang.page_prev}</a> <a href="{$pager.page_next}">{$lang.page_next}</a> <a href="{$pager.page_last}">{$lang.page_last}</a> </span>
    <!--{foreach from=$pager.search key=key item=item}-->
      {if $key eq 'keywords'}
          <input type="hidden" name="{$key}" value="{$item|escape:decode_url}" />
        {else}
          <input type="hidden" name="{$key}" value="{$item}" />
      {/if}
    <!--{/foreach}-->
    <select name="page" id="page" onchange="selectPage(this)">
    {html_options options=$pager.array selected=$pager.page}
    </select>
</div>
<!--{else}-->
<div id="pager" class="pagebar">
<span class="f_l f6" style="margin-right:10px;">总计<b>{$pager.record_count}</b> 个记录</span>
<!-- {if $pager.page_first} --><a href="{$pager.page_first}">{$lang.page_first} ...</a><!-- {/if} -->
<!-- {if $pager.page_prev} --><a class="prev" href="{$pager.page_prev}">{$lang.page_prev}</a><!-- {/if} -->
<!-- {if $pager.page_count neq 1} -->
    <!--{foreach from=$pager.page_number key=key item=item}-->
      <!-- {if $pager.page eq $key} -->
      <span class="page_now">{$key}</span>
      <!-- {else} -->
      <a href="{$item}">[{$key}]</a>
      <!-- {/if} -->
    <!--{/foreach}-->
<!-- {/if} -->
<!-- {if $pager.page_next} --><a class="next" href="{$pager.page_next}">{$lang.page_next}</a><!-- {/if} -->
<!-- {if $pager.page_last} --><a class="last" href="{$pager.page_last}">...{$lang.page_last}</a><!-- {/if} -->
<!-- {if $pager.page_kbd} -->
    <!--{foreach from=$pager.search key=key item=item}-->
      {if $key eq 'keywords'}
          <input type="hidden" name="{$key}" value="{$item|escape:decode_url}" />
        {else}
          <input type="hidden" name="{$key}" value="{$item}" />
      {/if}
    <!--{/foreach}-->
    <kbd style="float:left; margin-left:8px; position:relative; bottom:3px;"><input type="text" name="page" onkeydown="if(event.keyCode==13)selectPage(this)" size="3" class="B_blue" /></kbd>
    <!-- {/if} -->
</div>
<!-- {/if} -->
</form>
<!--翻页 END-->

 

PHP生成文字水印代码

<?php

setWater('img/999.jpg','',"for:小梅 为什么放弃治疗!",'105,0,0',2,'FZLBJW.TTF','text',24);
/*
$imgSrc:目标图片,可带相对目录地址,
$markImg:水印图片,可带相对目录地址,支持PNG和GIF两种格式,如水印图片在执行文件mark目录下,可写成:mark/mark.gif
$markText:给图片添加的水印文字
$TextColor:水印文字的字体颜色
$markPos:图片水印添加的位置,取值范围:0~9
0:随机位置,在1~8之间随机选取一个位置
1:顶部居左 2:顶部居中 3:顶部居右 4:左边居中
5:图片中心 6:右边居中 7:底部居左 8:底部居中 9:底部居右
$fontType:具体的字体库,可带相对目录地址
$markType:图片添加水印的方式,img代表以图片方式,text代表以文字方式添加水印
$fontSize: 字体大小
*/
function setWater($imgSrc,$markImg,$markText,$TextColor,$markPos,$fontType,$markType,$fontSize)
{
    $srcInfo = @getimagesize($imgSrc);
    $srcImg_w = $srcInfo[0];
    $srcImg_h = $srcInfo[1];
    switch ($srcInfo[2]) 
    { 
        case 1: 
            $srcim =imagecreatefromgif($imgSrc); 
            break; 
        case 2: 
            $srcim =imagecreatefromjpeg($imgSrc); 
            break; 
        case 3: 
            $srcim =imagecreatefrompng($imgSrc); 
            break; 
        default: 
            die("不支持的图片文件类型"); 
            exit; 
    }

    if(!strcmp($markType,"img"))
    {
        if(!file_exists($markImg) || empty($markImg))
        {
            return;
        }

        $markImgInfo = @getimagesize($markImg);
        $markImg_w    = $markImgInfo[0];
        $markImg_h    = $markImgInfo[1];

        if($srcImg_w < $markImg_w || $srcImg_h < $markImg_h)
        {
            return;
        }

        switch ($markImgInfo[2]) 
        { 
            case 1: 
                $markim =imagecreatefromgif($markImg); 
                break; 
            case 2: 
                $markim =imagecreatefromjpeg($markImg); 
                break; 
            case 3: 
                $markim =imagecreatefrompng($markImg); 
                break; 
            default: 
                die("不支持的水印图片文件类型"); 
                exit; 
        }

        $logow = $markImg_w;
        $logoh = $markImg_h;
    }

    if(!strcmp($markType,"text"))
    {
        // $fontSize = 16;
        if(!empty($markText))
        {
            if(!file_exists($fontType))
            {
                return;
            }
        }
        else {
            return;
        }

        $box = @imagettfbbox($fontSize, 0, $fontType,$markText);
        $logow = max($box[2], $box[4]) - min($box[0], $box[6]);
        $logoh = max($box[1], $box[3]) - min($box[5], $box[7]);
    }

    if($markPos == 0)
    {
        $markPos = rand(1, 9);
    }

    switch($markPos)
    {
        case 1:
            $x = +5;
            $y = +5;
            break;
        case 2:
            $x = ($srcImg_w - $logow) / 2;
            $y = +5+45;
            break;
        case 3:
            $x = $srcImg_w - $logow - 5;
            $y = +15;
            break;
        case 4:
            $x = +5;
            $y = ($srcImg_h - $logoh) / 2;
            break;
        case 5:
            $x = ($srcImg_w - $logow) / 2;
            $y = ($srcImg_h - $logoh) / 2;
            break;
        case 6:
            $x = $srcImg_w - $logow - 5;
            $y = ($srcImg_h - $logoh) / 2;
            break;
        case 7:
            $x = +5;
            $y = $srcImg_h - $logoh - 5;
            break;
        case 8:
            $x = ($srcImg_w - $logow) / 2;
            $y = $srcImg_h - $logoh - 5;
            break;
        case 9:
            $x = $srcImg_w - $logow - 5;
            $y = $srcImg_h - $logoh -5;
            break;
        default: 
            echo ("此位置不支持"); 
            exit;
    }

    $dst_img = @imagecreatetruecolor($srcImg_w, $srcImg_h);

    imagecopy ( $dst_img, $srcim, 0, 0, 0, 0, $srcImg_w, $srcImg_h);

    if(!strcmp($markType,"img"))
    {
        imagecopy($dst_img, $markim, $x, $y, 0, 0, $logow, $logoh);
        imagedestroy($markim);
    }

    if(!strcmp($markType,"text"))
    {
        $rgb = explode(',', $TextColor);

        $color = imagecolorallocate($dst_img, $rgb[0], $rgb[1], $rgb[2]);
        imagettftext($dst_img, $fontSize, 0, $x, $y, $color, $fontType,$markText);
    } 
    switch ($srcInfo[2]) 
    { 
        case 1:
            // imagegif($dst_img, $imgSrc); 
			header("content-type: image/gif");
            imagegif($dst_img); 
            break; 
        case 2: 
            // imagejpeg($dst_img, $imgSrc); 
			header("content-type: image/jpeg");
            imagejpeg($dst_img); 
            break; 
        case 3: 
            // imagepng($dst_img, $imgSrc); 
			header("content-type: image/png");
            imagepng($dst_img); 
            break;
        default: 
            die("不支持的水印图片文件类型"); 
            exit; 
    }

    imagedestroy($dst_img);
    imagedestroy($srcim);
}

?>

 

云服务器连接RDS不稳定问题解决方案

nscd服务开启后会减少因为DNS不稳定造成的云服务器连接RDS无法解析的问题。

详细的开启办法如下:

1. 安装nscd

首先检查服务器上有无安装nscd,如果没有(如果已经安装直接启动nscd服务即可,参考第二步)

在云服务器上执行命令

Ubuntu和Debian系统执行:apt-get install nscd

CentOS及Red Hat系统执行:yum install nscd

2. 启动nscd

安装nscd之后执行 : service nscd start

执行命令后显示如下

3. 检查nscd是否启动

启动nscd之后执行命令: ps -ef|grep nscd

4. 设置nscd开机启动

chkconfig –list|grep nscd

chkconfig –livel 2345 nscd on

5. 修改dns解析文件

请在/etc/resolv.conf文件中添加:options timeout:1 attempts:1

wordpress去除wordpress.org增加登陆框

首先找到这个文件,位于/wp-includes/下的default-widgets.php

去掉wordpress.org,删除

<li><a href="http://wordpress.org/" title="<?php echo esc_attr(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>">WordPress.org</a></li>

删除RSS

<li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo esc_attr(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>

 

<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo esc_attr(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>

删除 <li><?php wp_loginout(); ?></li> 这段代码,然后改为如下代码

<li><?php if (!(current_user_can('level_0'))){ ?>
<form action="<?php echo get_option('home'); ?>/wp-login.php" method="post">
<input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="20" /><br />
<input type="password" name="pwd" id="pwd" size="20" /><br>
<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> 记住密码</label>
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" /> <input type="submit" name="submit" value="登录" class="button" />
</p>
</form>
<a href="<?php echo get_option('home'); ?>/wp-login.php?action=lostpassword">忘记密码</a>
<?php } else { ?>
<a href="<?php echo wp_logout_url( get_bloginfo('url') ); ?>" title="">退出登录</a>
<?php }?></li>

 

 

利用aliyunOSS同步网站图片

将本程序解压到任意目录, 并进入该目录,运行:

sudo python setup.py

配置文件:

HOST = "oss-internal.aliyuncs.com"
ACCESS_ID = "2222"
SECRET_ACCESS_KEY = "222222"
oss_mappers = [{'bucket': tocoolaj', 'local_folders': ['/data/coolaj']}]

即为同步coolaj文件夹到tocoolaj的bucket

 

ossync.tar

nginx 301跳转到带www域名方法rewrite

如果www.coolaj.cn coolaj.cn都解析到www.coolaj.cn

打开 nginx.conf文件找到你的server配置段:

server
{
listen 80;
server_name www.coolaj.cn coolaj.cn;
if ($host != 'www.coolaj.cn' ) {
    rewrite ^/(.*)$ http://www.coolaj.cn/$1 permanent;
}

 

 

插件冲突,ipad屏幕图标变小而且分散的恢复办法

大伙都是刚越狱,而且像我这样原生4.3.5自打买上3、4个月就没尝过越狱的滋味~

近乎疯狂的装插件~测试插件~美化~破解~~

终于,有两个插件冲突了~

ipad屏幕变成图标小~而且分散的样子~点进程序~全部变成iphone程序界面~但是触屏没反应~

痛苦啊!

上网查了查~貌似不少同志都有这样的情况~

貌似最有效的就是进/library/Mobilesubstrate/Dynamiclibraries/
把你觉得可能导致冲突的插件 在后面加上 .old的后缀
再重启测试~
优先推荐这种方法~如果实在记不起是哪个插件引起的~接着看下面~

这样应该是有效的~但关键是我们疯狂的装插件,哪知道那个是冲突的呀!

其实,很简单

全删了就好了!

不用担心,那些都是动态挂载的~不是插件的源程序~

删了就没问题了,也没什么影响,我自己也是这么恢复的

所以给大家的建议是:装插件一定要慎重
其实美化,插件什么的都是浮云,新鲜劲儿过了,什么都没了~吼吼

希望大家支持哦,可以留着备用,记性好的就直接记住是/library/Mobilesubstrate/Dynamiclibraries/这里哦!

保不准那天手Jian~像我一样~

以前做的采集QQ号码程序

<?php
header("Content-type: text/html; charset=utf-8");
require_once 'database.php';
//set_time_limit(0);
//ignore_user_abort();
function writelog($log){
	$log_file="rizhi.txt";
	$fp = fopen($log_file,'a');
	fwrite($fp,date("Y-m-d H:i:s",time())."		".$log."\r\n");
	fclose($fp);
}
function writelog2($log){
	$log_file="QQMAIL.txt";
	$fp = fopen($log_file,'a');
	fwrite($fp,$log."\r\n");
	fclose($fp);
}
ignore_user_abort();           // 即使Client断开(如关掉浏览器),PHP脚本也可以继续执行.
set_time_limit(0);             // 执行时间为无限制,php默认的执行时间是30秒,通过set_time_limit(0)可以让程序无限制的执行下去

$bb = 0 ;
writelog('开始采集!');
echo '开始采集!<br><hr>';

for($nl=24;$nl<=30;$nl++){//年龄
	$nl++;
	$nl2=$nl +1;
	for($yue=1;$yue<=12;$yue++){//月
		for($ri=1;$ri<=31;$ri++){//日
			for($i=0;$i<100;$i++){//页数
				$jishu =$i+1;
				echo "<font color = red>最低年龄:".$nl."最高年龄:".$nl2."     ".$yue."月".$ri."日  ".$jishu."%</font>";
				echo "<br>";
				writelog("最低年龄:".$nl."最高年龄:".$nl2."     ".$yue."月".$ri."日  第".$i."页");
				$url="http://soren.qzone.qq.com/cgi-bin/soren/cgi_userinfo_search?sex=-1&a1=".$nl."&a2=".$nl2."&pv=11&ct=1100&hp=0&hc=0&at=-1&month=".$yue."&day=".$ri."&mr=-1&bt=-1&cr=&cn=&cap=0&cac=0&idol=&game=&it=&sport=&book=&tv=&cloth=&cosm=&place=&interest=&begin=".$i."&bSimple=0";
				$ch = curl_init();
				curl_setopt ($ch, CURLOPT_URL, $url);
				curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
				curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
				$content = curl_exec($ch);
				preg_match_all('/id=\"portrait_(.*?)\" onclick/is',$content,$qq);
				foreach($qq[1] as $value){

					$coolaj = trim($value)."@qq.com";
					$sql = "select * from mail where mails = '".$coolaj."'";
					$rs2 = mysql_query($sql, $connect) or die("Invalid query: " . mysql_error());
					$cool =  mysql_fetch_row ($rs2);
					if(is_array($cool)){
						writelog("插入失败->".$coolaj."已经存在!");
					}else{
						$rs = mysql_query("insert into mail VALUES('','".$coolaj."','".$i."','QQ采集')", $connect) or die("Invalid query: " . mysql_error());
						if($rs){
							$bb++;
							echo $showtime=date("Y-m-d H:i:s");
							echo "插入<font color=red>第".$bb."个</font><font color=blue>".$coolaj."</font>成功!<br>";
							writelog("插入第".$bb."个".$coolaj."成功!");
							writelog2($coolaj);
						}else{
							writelog("插入".$coolaj."失败!");
						}
					}

				}
			}
		}
	}
}
echo "<script>alert('采集完成!')</script>";

 

<?php
$_POST=sql_injection($_POST);
$_GET=sql_injection($_GET);
function sql_injection($content)
{
 if (get_magic_quotes_gpc())
 {
  if (is_array($content))
  {
   foreach ($content as $key=>$value)
   {
    $content[$key] = str_replace("'","\"",stripslashes($value));
   }
  }
  else
  {
    $content[$key] = str_replace("'","\"",stripslashes($content));
  }
 }
 return $content;
}

$hostname_conn = "localhost";
$database_conn = "test";
$username_conn = "root";
$password_conn = "";
$connect = mysql_pconnect($hostname_conn, $username_conn, $password_conn,true) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_conn, $connect);
mysql_query("set NAMES 'UTF8'");
date_default_timezone_set('PRC');
?>