<?php
/*
* Created on 2010-3-11
* author:zhangfei
*我的验证码类
*/
session_start();
class Check_Class{
public $h_img ;
public $c_back ;
public $c_front ;
//构造函数
function Check_Class(){
$h_img = imagecreate(100,30);
$c_back = imagecolorallocate($h_img,0,0,0);
$c_front = imagecolorallocate($h_img,255,255,255);
$_SESSION[randstr]=$randm_string = $this->random(5);//用session保存起来用以后面判断
$this->getLine($h_img);
$this->getPoint($h_img);
$this->paintString($h_img,$randm_string,$c_front);
//显示图片
header("Content-type: image/jpeg");
imagejpeg($h_img);
imagedestroy($h_img);
}
//产生随机字符串,包括数字和大小写字母
function random($length)
{
$hash = "";
$chars = "CEFGHIJKLMNOPQRSTUVWXYZ0123456789cefghijklmnopqrstuvwxyz";
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++)
{
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}
//画干扰线的函数
function getLine($h){
for($j=0;$j<5;$j++){
//定义线条
$c_line = imagecolorallocate($h,rand(0,255),rand(0,255),rand(0,255));
//在图片上划线
imageline($h,rand(0,100),rand(0,30),rand(0,100),rand(0,30),$c_line);
}
}
//画噪点
function getPoint($h){
for($ii=0;$ii<400;$ii++){
$c_point = imagecolorallocate($h,rand(0,255),rand(0,255),rand(0,255));//定义噪点颜色
imagesetpixel($h,rand()%100,rand()%30,$c_point);
}
}
//画字符串
function paintString($h,$rd_str,$c_f){
imagestring($h,rand(4,6),rand(1,50),rand(1,15),$rd_str,$c_f);
}
}
$chek = new Check_Class();
?>
抓取到的内容在通过正则表达式做一下过滤就得到了你想要的内容,至于如何用正则表达式过滤,在这里就不做介绍了,有兴趣的,以下就是几种常用的用php抓取网页中的内容的方法。
1.file_get_contents
PHP代码
复制代码 代码如下:
<?php
$url = "http://www.jb51.net";
$contents = file_get_contents($url);
// ......
Google 在一年前发布了Google App Engine (GAE) 。这是一个免费的 App Engine 主机,可以让你的每个Application(免费的最多有10个)有1GB的磁盘空间和43.6个CPU小时与10GB的上传和10GB的下载带宽,以及2000个电子邮件。如果你需要地更多,那就是付钱了。
GAE 最近发布了正式支持Java的通知。于是,互 ......