<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>奔向远方 &#187; PHP</title>
	<atom:link href="http://www.tisswb.com/archives/category/web-technology/php-web-technology/feed" rel="self" type="application/rss+xml" />
	<link>http://www.tisswb.com</link>
	<description>结婚开始倒计时了，高兴~</description>
	<lastBuildDate>Tue, 19 Jul 2011 09:30:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>php编译参数的含义</title>
		<link>http://www.tisswb.com/archives/576.html</link>
		<comments>http://www.tisswb.com/archives/576.html#comments</comments>
		<pubDate>Sat, 31 Jul 2010 16:42:44 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[Web服务器]]></category>
		<category><![CDATA[服务器]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=576</guid>
		<description><![CDATA[今天整理编译php的时候的参数，在网上搜集了一些关于configure参数的资料：
./configure
&#8211;prefix=/usr/local/php                                   php 安装目录
&#8211;with-apxs2=/usr/local/apache/bin/apxs
&#8211;with-config-file-path=/usr/local/php/etc               指定php.ini位置
&#8211;with-mysql=/usr/local/mysql                        mysql安装目录，对mysql的支持
&#8211;with-mysqli=/usr/local/mysql/bin/mysql_config            mysqli文件目录,优化支持
<span class="readmore"><a href="http://www.tisswb.com/archives/576.html" title="php编译参数的含义" target="_blank">阅读全文——共2772字</a></span>]]></description>
			<content:encoded><![CDATA[<p>今天整理编译php的时候的参数，在网上搜集了一些关于configure参数的资料：</p>
<p>./configure</p>
<p>&#8211;prefix=/usr/local/php                                   <a target="_self"><strong>php</strong> </a>安装目录<br />
&#8211;with-apxs2=/usr/local/apache/bin/apxs<br />
&#8211;with-config-file-path=/usr/local/php/etc               指定php.ini位置<br />
&#8211;with-mysql=/usr/local/mysql                        mysql安装目录，对mysql的支持<br />
&#8211;with-mysqli=/usr/local/mysql/bin/mysql_config            mysqli文件目录,优化支持<br />
&#8211;enable-safe-mode                              打开安全模式<br />
&#8211;enable-ftp                                 打开ftp的支持<br />
&#8211;enable-zip                                 打开对zip的支持<br />
&#8211;with-bz2                                    打开对bz2文件的支持                        <br />
&#8211;with-jpeg-dir                                 打开对jpeg图片的支持<br />
&#8211;with-png-dir                                 打开对png图片的支持<br />
&#8211;with-freetype-dir                              打开对freetype字体库的支持<br />
&#8211;without-iconv                                 关闭iconv函数，种字符集间的转换<br />
&#8211;with-libxml-dir                                 打开libxml2库的支持<br />
&#8211;with-xmlrpc                                 打开xml-rpc的c语言<br />
&#8211;with-zlib-dir                                 打开zlib库的支持<br />
&#8211;with-gd                                    打开gd库的支持<br />
&#8211;enable-gd-native-ttf                           支持TrueType字符串函数库<br />
&#8211;with-curl                                    打开curl浏览工具的支持<br />
&#8211;with-curlwrappers                              运用curl工具打开url流<br />
&#8211;with-ttf                                    打开freetype1.*的支持，可以不加了<br />
&#8211;with-xsl                                     打开XSLT 文件支持，扩展了libxml2库 ，需要libxslt软件<br />
&#8211;with-gettext                                 打开gnu 的gettext 支持，编码库用到<br />
&#8211;with-pear                      打开pear命令的支持，php扩展用的<br />
&#8211;enable-calendar                  打开日历扩展功能<br />
&#8211;enable-mbstring                  多字节，字符串的支持<br />
&#8211;enable-bcmath                  打开图片大小调整,用到zabbix监控的时候用到了这个模块<br />
&#8211;enable-sockets                  打开 sockets 支持<br />
&#8211;enable-exif                      图片的元数据支持<br />
&#8211;enable-magic-quotes               魔术引用的支持<br />
&#8211;disable-rpath                     关闭额外的运行库文件<br />
&#8211;disable-debug                  关闭调试模式<br />
&#8211;with-mime-magic=/usr/share/file/magic.mime      魔术头文件位置</p>
<p>cgi方式安装才用的<a target="_self"><strong>参数</strong> </a><br />
&#8211;enable-fpm                     打上php-fpm 补丁后才有这个参数，cgi方式安装的启动程序<br />
&#8211;enable-fastcgi                  支持fastcgi方式启动php<br />
&#8211;enable-force-cgi-redirect             同上 ,帮助里没有解释<br />
&#8211;with-ncurses                     支持ncurses 屏幕绘制以及基于文本终端的图形互动功能的动态库<br />
&#8211;enable-pcntl                     freeTDS需要用到的，可能是链接mssql 才用到</p>
<p>mhash和mcrypt算法的扩展<br />
&#8211;with-mcrypt                     算法<br />
&#8211;with-mhash                     算法</p>
<p>&#8211;with-gmp<br />
&#8211;enable-inline-optimization<br />
&#8211;with-openssl                     openssl的支持，加密传输时用到的<br />
&#8211;enable-dbase<br />
&#8211;with-pcre-dir=/usr/local/bin/pcre-config      perl的正则库案安装位置<br />
&#8211;disable-dmalloc<br />
&#8211;with-gdbm                     dba的gdbm支持<br />
&#8211;enable-sigchild<br />
&#8211;enable-sysvsem<br />
&#8211;enable-sysvshm<br />
&#8211;enable-zend-multibyte               支持zend的多字节<br />
&#8211;enable-mbregex<br />
&#8211;enable-wddx<br />
&#8211;enable-shmop<br />
&#8211;enable-soap</p>
<p>来源：<a href="http://nedvedheqing.javaeye.com/blog/545632">http://nedvedheqing.javaeye.com/blog/545632</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/576.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP中$_SERVER的详细参数与说明</title>
		<link>http://www.tisswb.com/archives/560.html</link>
		<comments>http://www.tisswb.com/archives/560.html#comments</comments>
		<pubDate>Thu, 27 May 2010 13:54:51 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=560</guid>
		<description><![CDATA[最近经常用到PHP的$_SERVER常量，都是零零碎碎的随用随查，今天整理一下，并且把$_SERVER的详细参数及说明整理一下：
$_SERVER['PHP_SELF'] #当前正在执行脚本的文件名，与 document root相关。
$_SERVER['argv'] #传递给该脚本的参数。
$_SERVER['argc'] #包含传递给程序的命令行参数的个数（如果运行在命令行模式）。
$_SERVER['GATEWAY_INTERFACE'] #服务器使用的 CGI 规范的版本。例如，“CGI/1.1”。
$_SERVER['SERVER_NAME'] #当前运行脚本所在服务器主机的名称。
$_SERVER['SERVER_SOFTWARE'] #服务器标识的字串，在响应请求时的头部中给出。
$_SERVER['SERVER_PROTOCOL'] #请求页面时通信协议的名称和版本。例如，“HTTP/1.0”。
<span class="readmore"><a href="http://www.tisswb.com/archives/560.html" title="PHP中$_SERVER的详细参数与说明" target="_blank">阅读全文——共1706字</a></span>]]></description>
			<content:encoded><![CDATA[<p>最近经常用到PHP的$_SERVER常量，都是零零碎碎的随用随查，今天整理一下，并且把$_SERVER的详细参数及说明整理一下：</p>
<p><code>$_SERVER['PHP_SELF'] #当前正在执行脚本的文件名，与 document root相关。<br />
$_SERVER['argv'] #传递给该脚本的参数。<br />
$_SERVER['argc'] #包含传递给程序的命令行参数的个数（如果运行在命令行模式）。<br />
$_SERVER['GATEWAY_INTERFACE'] #服务器使用的 CGI 规范的版本。例如，“CGI/1.1”。<br />
$_SERVER['SERVER_NAME'] #当前运行脚本所在服务器主机的名称。<br />
$_SERVER['SERVER_SOFTWARE'] #服务器标识的字串，在响应请求时的头部中给出。<br />
$_SERVER['SERVER_PROTOCOL'] #请求页面时通信协议的名称和版本。例如，“HTTP/1.0”。<br />
$_SERVER['REQUEST_METHOD'] #访问页面时的请求方法。例如：“GET”、“HEAD”，“POST”，“PUT”。<br />
$_SERVER['QUERY_STRING'] #查询(query)的字符串。<br />
$_SERVER['DOCUMENT_ROOT'] #当前运行脚本所在的文档根目录。在服务器配置文件中定义。<br />
$_SERVER['HTTP_ACCEPT'] #当前请求的 Accept: 头部的内容。<br />
$_SERVER['HTTP_ACCEPT_CHARSET'] #当前请求的 Accept-Charset: 头部的内容。例如：“iso-8859-1,*,utf-8”。<br />
$_SERVER['HTTP_ACCEPT_ENCODING'] #当前请求的 Accept-Encoding: 头部的内容。例如：“gzip”。<br />
$_SERVER['HTTP_ACCEPT_LANGUAGE']#当前请求的 Accept-Language: 头部的内容。例如：“en”。<br />
$_SERVER['HTTP_CONNECTION'] #当前请求的 Connection: 头部的内容。例如：“Keep-Alive”。<br />
$_SERVER['HTTP_HOST'] #当前请求的 Host: 头部的内容。<br />
$_SERVER['HTTP_REFERER'] #链接到当前页面的前一页面的 URL 地址。<br />
$_SERVER['HTTP_USER_AGENT'] #当前请求的 User_Agent: 头部的内容。<br />
$_SERVER['HTTPS'] — 如果通过https访问,则被设为一个非空的值(on)，否则返回off<br />
$_SERVER['REMOTE_ADDR'] #正在浏览当前页面用户的 IP 地址。<br />
$_SERVER['REMOTE_HOST'] #正在浏览当前页面用户的主机名。<br />
$_SERVER['REMOTE_PORT'] #用户连接到服务器时所使用的端口。<br />
$_SERVER['SCRIPT_FILENAME'] #当前执行脚本的绝对路径名。<br />
$_SERVER['SERVER_ADMIN'] #管理员信息<br />
$_SERVER['SERVER_PORT'] #服务器所使用的端口<br />
$_SERVER['SERVER_SIGNATURE'] #包含服务器版本和虚拟主机名的字符串。<br />
$_SERVER['PATH_TRANSLATED'] #当前脚本所在文件系统（不是文档根目录）的基本路径。<br />
$_SERVER['SCRIPT_NAME'] #包含当前脚本的路径。这在页面需要指向自己时非常有用。<br />
$_SERVER['REQUEST_URI'] #访问此页面所需的 URI。例如，“/index.html”。<br />
$_SERVER['PHP_AUTH_USER'] #当 PHP 运行在 Apache 模块方式下，并且正在使用 HTTP 认证功能，这个变量便是用户输入的用户名。<br />
$_SERVER['PHP_AUTH_PW'] #当 PHP 运行在 Apache 模块方式下，并且正在使用 HTTP 认证功能，这个变量便是用户输入的密码。<br />
$_SERVER['AUTH_TYPE'] #当 PHP 运行在 Apache 模块方式下，并且正在使用 HTTP 认证功能，这个变量便是认证的类型。</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/560.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在ubuntu9.04下安装ZendStudio7.0详解</title>
		<link>http://www.tisswb.com/archives/517.html</link>
		<comments>http://www.tisswb.com/archives/517.html#comments</comments>
		<pubDate>Sun, 16 Aug 2009 14:31:39 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[服务器]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[ZendStudio]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=517</guid>
		<description><![CDATA[ZendStudio7绝对是php编辑的神器，最近一段时间使用的是不亦乐乎。但是最近工作环境转移到了Ubuntu上了，还是相当希望能够使用ZS7。当然，zend公司还是给我们提供了linux下的安装文件了，由于是初次在linux下面安装ZendStudio7，下面记录一下安装步骤细节，以备以后查阅：
1.下载zendstudio的linux版本，我下载的地址是：http://downloads.zend.com/studio-eclipse/7.0.0/ZendStudio-7.0.0.tar.gz
2.安装支持环境，zendstudio7需要jre支持，所以需要安装一下
sudo apt-get instll sun-java6-jre sun-java6-jdk
3.解压缩ZendStudio7的压缩包，把内容解压缩到个人的home目录中，解压缩出来的文件是一个叫ZendStudio7_0_0.bin的文件
<span class="readmore"><a href="http://www.tisswb.com/archives/517.html" title="在ubuntu9.04下安装ZendStudio7.0详解" target="_blank">阅读全文——共511字</a></span>]]></description>
			<content:encoded><![CDATA[<p>ZendStudio7绝对是php编辑的神器，最近一段时间使用的是不亦乐乎。但是最近工作环境转移到了Ubuntu上了，还是相当希望能够使用ZS7。当然，zend公司还是给我们提供了linux下的安装文件了，由于是初次在linux下面安装ZendStudio7，下面记录一下安装步骤细节，以备以后查阅：</p>
<p>1.下载zendstudio的linux版本，我下载的地址是：<a title="zendstudio7的官方下载地址" href="http://downloads.zend.com/studio-eclipse/7.0.0/ZendStudio-7.0.0.tar.gz">http://downloads.zend.com/studio-eclipse/7.0.0/ZendStudio-7.0.0.tar.gz</a></p>
<p>2.安装支持环境，zendstudio7需要jre支持，所以需要安装一下<br />
<code>sudo apt-get instll sun-java6-jre sun-java6-jd</code>k</p>
<p>3.解压缩ZendStudio7的压缩包，把内容解压缩到个人的home目录中，解压缩出来的文件是一个叫ZendStudio7_0_0.bin的文件</p>
<p>4.使用如下命令安装这个bin文件<br />
<code>./ZendStudio7_0_0.bin</code></p>
<p>5.再往后的安装步骤就跟在window下面安装一样了，一直点下一步就可以了</p>
<p>安装完成后的配置也跟windows下面的一样了，这里我就不多说了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/517.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php单引号和双引号的区别</title>
		<link>http://www.tisswb.com/archives/505.html</link>
		<comments>http://www.tisswb.com/archives/505.html#comments</comments>
		<pubDate>Tue, 26 May 2009 06:39:03 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php学习点滴]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=505</guid>
		<description><![CDATA[平时很少注意到这个细节，一直以为PHP中单引号和双引号是互通的，直到有一天，发现单引号和双引号确实存在区别的时候，就仔细研究了一下，有了下面这段文字。
&#8221; &#8221; 双引号里面的字段会经过编译器解释，然后再当作HTML代码输出。
&#8216; &#8216; 单引号里面的不进行解释，直接输出。
从字面意思上就可以看出，单引号比双引号要快了。
例如：
$abc=&#8217;my name is tome&#8217;;
echo $abc //结果是:my name is tom
echo &#8216;$abc&#8217; //结果是:$abc
echo &#8220;$abc&#8221; //结果是:my name is tom
特别在使用MYSQL语句的时候，双引号和单引号的用法让新手不知所措，在这里，举个例子，来进行说明。
<span class="readmore"><a href="http://www.tisswb.com/archives/505.html" title="php单引号和双引号的区别" target="_blank">阅读全文——共957字</a></span>]]></description>
			<content:encoded><![CDATA[<p>平时很少注意到这个细节，一直以为PHP中单引号和双引号是互通的，直到有一天，发现单引号和双引号确实存在区别的时候，就仔细研究了一下，有了下面这段文字。</p>
<p>&#8221; &#8221; 双引号里面的字段会经过编译器解释，然后再当作HTML代码输出。</p>
<p>&#8216; &#8216; 单引号里面的不进行解释，直接输出。</p>
<p>从字面意思上就可以看出，单引号比双引号要快了。</p>
<p>例如：<br />
$abc=&#8217;my name is tome&#8217;;<br />
echo $abc //结果是:my name is tom<br />
echo &#8216;$abc&#8217; //结果是:$abc<br />
echo &#8220;$abc&#8221; //结果是:my name is tom</p>
<p>特别在使用MYSQL语句的时候，双引号和单引号的用法让新手不知所措，在这里，举个例子，来进行说明。</p>
<p>假设查询条件中使用的是常量，例如：</p>
<p>select    *    from    abc_table where user_name=&#8217;abc&#8217;;</p>
<p>SQL语句可以写成:</p>
<p>SQLstr = &#8220;select    *    from abc_table where user _name= &#8216;abc&#8217;&#8221; ;</p>
<p>假设查询条件中使用的是变量，例如：</p>
<p>$user_name = $_REQUEST['user_name']; //字符串变量</p>
<p>或</p>
<p>$user=array (&#8220;name&#8221;=&gt; $_REQUEST['user_name‘,"age"=&gt;$_REQUEST['age'];//数组变量</p>
<p>SQL语句就可以写成：</p>
<p>SQLstr = &#8220;select    *    from abc_table where user_name = &#8216; &#8221; . $user_name . &#8221; &#8216; &#8220;;</p>
<p>SQLstr = &#8220;select * from abc_table where user_name = &#8216; &#8221; . $user["name"] . &#8221; &#8216; &#8220;;</p>
<p>对比一下:</p>
<p>SQLstr=&#8221;select * from abc_table where user_name = &#8216; abc &#8216; &#8221; ;</p>
<p>SQLstr=&#8221;select * from abc_table where user_name =&#8217; &#8221; . $user _name . &#8221; &#8216; &#8220;;</p>
<p>SQLstr=&#8221;select * from abc_table where user_name =&#8217; &#8221; . $user["name"] . &#8221; &#8216; &#8220;;</p>
<p>SQLstr可以分解为以下3个部分:<br />
1：&#8221;select * from table where user_name = &#8216; &#8221; //固定SQL语句<br />
2：$user //变量<br />
3：&#8221; &#8216; &#8221;<br />
1,2,3部分字符串之间用&#8221;.&#8221; 来连接</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/505.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP中file_get_contents函数超时的几种解决方法</title>
		<link>http://www.tisswb.com/archives/498.html</link>
		<comments>http://www.tisswb.com/archives/498.html#comments</comments>
		<pubDate>Sun, 24 May 2009 17:33:01 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=498</guid>
		<description><![CDATA[在使用file_get_contents函数的时候，经常会出现超时的情况，在这里要通过查看一下错误提示，看看是哪种错误，比较常见的是读取超时，这种情况大家可以通过一些方法来尽量的避免或者解决。这里就简单介绍两种：
一、增加超时的时间限制
这里需要注意：set_time_limit只是设置你的PHP程序的超时时间，而不是file_get_contents函数读取URL的超时时间。
我一开始以为set_time_limit也能影响到file_get_contents，后来经测试，是无效的。真正的修改file_get_contents延时可以用resource $context的timeout参数：
$opts = array(
'http'=>array(
'method'=>"GET",
'timeout'=>60,
)
); 
<span class="readmore"><a href="http://www.tisswb.com/archives/498.html" title="PHP中file_get_contents函数超时的几种解决方法" target="_blank">阅读全文——共683字</a></span>]]></description>
			<content:encoded><![CDATA[<p>在使用file_get_contents函数的时候，经常会出现超时的情况，在这里要通过查看一下错误提示，看看是哪种错误，比较常见的是读取超时，这种情况大家可以通过一些方法来尽量的避免或者解决。这里就简单介绍两种：</p>
<p>一、增加超时的时间限制</p>
<p>这里需要注意：set_time_limit只是设置你的PHP程序的超时时间，而不是file_get_contents函数读取URL的超时时间。<br />
我一开始以为set_time_limit也能影响到file_get_contents，后来经测试，是无效的。真正的修改file_get_contents延时可以用resource $context的timeout参数：</p>
<p><code>$opts = array(<br />
'http'=>array(<br />
'method'=>"GET",<br />
'timeout'=>60,<br />
)<br />
); </p>
<p>$context = stream_context_create($opts); </p>
<p>$html =file_get_contents('http://www.example.com', false, $context);<br />
fpassthru($fp);<br />
</code></p>
<p>二、一次有延时的话那就多试几次</p>
<p>有时候失败是因为网络等因素造成，没有解决办法，但是可以修改程序，失败时重试几次，仍然失败就放弃，因为file_get_contents()如果失败将返回 FALSE，所以可以下面这样编写代码：</p>
<p><code>$cnt=0;<br />
while($cnt < 3 &#038;&#038; ($str=@file_get_contents('http...'))===FALSE) $cnt++; </code></p>
<p>以上只是我搜集整理的一些小技巧，希望能找到更好的技巧。</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/498.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php采集利器——模拟浏览器类snoopy应用</title>
		<link>http://www.tisswb.com/archives/299.html</link>
		<comments>http://www.tisswb.com/archives/299.html#comments</comments>
		<pubDate>Sun, 15 Mar 2009 17:20:15 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php学习点滴]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=299</guid>
		<description><![CDATA[研究php页面数据采集的时候，无意中发现了snoopy这个类，snoopy是用php写的用以模拟浏览器功能的php类，它可以模拟访问，提交表单到你需要登录的web服务器端，同时提供了筛选信息的功能，让你可以根据需要取得自己想要的信息。
snoopy的官方网站：http://sourceforge.net/projects/snoopy/
Snoopy是一个php类，用来模拟浏览器的功能，可以获取网页内容，发送表单。
Snoopy 正确运行需要你的服务器的 PHP 版本在 4 以上，并且支持 PCRE（Perl Compatible Regular Expressions），基本的 LAMP 服务都支持。
下载snoopy
Snoopy的一些特点:
1抓取网页的内容 fetch
2 抓取网页的文本内容 (去除HTML标签) fetchtext
3抓取网页的链接，表单 fetchlinks fetchform
<span class="readmore"><a href="http://www.tisswb.com/archives/299.html" title="php采集利器——模拟浏览器类snoopy应用" target="_blank">阅读全文——共5360字</a></span>]]></description>
			<content:encoded><![CDATA[<p>研究php页面数据采集的时候，无意中发现了snoopy这个类，snoopy是用php写的用以模拟浏览器功能的php类，它可以模拟访问，提交表单到你需要登录的web服务器端，同时提供了筛选信息的功能，让你可以根据需要取得自己想要的信息。</p>
<p>snoopy的官方网站：<a href="http://sourceforge.net/projects/snoopy/" target="_blank">http://sourceforge.net/projects/snoopy/</a></p>
<p>Snoopy是一个php类，用来模拟浏览器的功能，可以获取网页内容，发送表单。</p>
<p>Snoopy 正确运行需要你的服务器的 PHP 版本在 4 以上，并且支持 PCRE（Perl Compatible Regular Expressions），基本的 LAMP 服务都支持。<br />
下载<a href="http://sourceforge.net/projects/snoopy/" target="_blank"><strong>snoopy</strong></a></p>
<p>Snoopy的一些特点:</p>
<p>1抓取网页的内容 fetch<br />
2 抓取网页的文本内容 (去除HTML标签) fetchtext<br />
3抓取网页的链接，表单 fetchlinks fetchform<br />
4 支持代理主机<br />
5支持基本的用户名/密码验证<br />
6 支持设置 user_agent, referer(来路), cookies 和 header content(头文件)<br />
7支持浏览器重定向，并能控制重定向深度<br />
8能把网页中的链接扩展成高质量的url(默认)<br />
9提交数据并且获取返回值<br />
10 支持跟踪HTML框架<br />
11支持重定向的时候传递cookies<br />
要求php4以上就可以了 由于本身是php一个类 无需扩支持 服务器不支持curl时候的最好选择，</p>
<p>类方法:</p>
<p>fetch($URI)<br />
———–</p>
<p>这是为了抓取网页的内容而使用的方法。<br />
$URI参数是被抓取网页的URL地址。<br />
抓取的结果被存储在 $this-&gt;results 中。<br />
如果你正在抓取的是一个框架，Snoopy将会将每个框架追踪后存入数组中，然后存入 $this-&gt;results。</p>
<p>fetchtext($URI)<br />
—————</p>
<p>本方法类似于fetch()，唯一不同的就是本方法会去除HTML标签和其他的无关数据，只返回网页中的文字内容。</p>
<p>fetchform($URI)<br />
—————</p>
<p>本方法类似于fetch()，唯一不同的就是本方法会去除HTML标签和其他的无关数据，只返回网页中表单内容(form)。</p>
<p>fetchlinks($URI)<br />
—————-</p>
<p>本方法类似于fetch()，唯一不同的就是本方法会去除HTML标签和其他的无关数据，只返回网页中链接(link)。<br />
默认情况下，相对链接将自动补全，转换成完整的URL。</p>
<p>submit($URI,$formvars)<br />
———————-</p>
<p>本方法向$URL指定的链接地址发送确认表单。$formvars是一个存储表单参数的数组。</p>
<p>submittext($URI,$formvars)<br />
————————–</p>
<p>本方法类似于submit()，唯一不同的就是本方法会去除HTML标签和其他的无关数据，只返回登陆后网页中的文字内容。</p>
<p>submitlinks($URI)<br />
—————-</p>
<p>本方法类似于submit()，唯一不同的就是本方法会去除HTML标签和其他的无关数据，只返回网页中链接(link)。<br />
默认情况下，相对链接将自动补全，转换成完整的URL。</p>
<p>类属性: (缺省值在括号里)</p>
<p>$host 连接的主机<br />
$port 连接的端口<br />
$proxy_host 使用的代理主机，如果有的话<br />
$proxy_port 使用的代理主机端口，如果有的话<br />
$agent 用户代理伪装 (Snoopy v0.1)<br />
$referer 来路信息，如果有的话<br />
$cookies cookies， 如果有的话<br />
$rawheaders 其他的头信息, 如果有的话<br />
$maxredirs 最大重定向次数， 0=不允许 (5)<br />
$offsiteok whether or not to allow redirects off-site. (true)<br />
$expandlinks 是否将链接都补全为完整地址 (true)<br />
$user 认证用户名, 如果有的话<br />
$pass 认证用户名, 如果有的话<br />
$accept http 接受类型 (image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*)<br />
$error 哪里报错, 如果有的话<br />
$response_code 从服务器返回的响应代码<br />
$headers 从服务器返回的头信息<br />
$maxlength 最长返回数据长度<br />
$read_timeout 读取操作超时 (requires PHP 4 Beta 4+)<br />
设置为0为没有超时<br />
$timed_out 如果一次读取操作超时了，本属性返回 true (requires PHP 4 Beta 4+)<br />
$maxframes 允许追踪的框架最大数量<br />
$status 抓取的http的状态<br />
$temp_dir 网页服务器能够写入的临时文件目录 (/tmp)<br />
$curl_path cURL binary 的目录, 如果没有cURL binary就设置为 false</p>
<p>以下是demo</p>
<div><code lang="php"><br />
[codesyntax lang="php"]</p>
<pre>include "Snoopy.class.php";
$snoopy = new Snoopy; 

$snoopy-&gt;proxy_host = "www.baidu.com";
$snoopy-&gt;proxy_port = "8080"; 

$snoopy-&gt;agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)";
$snoopy-&gt;referer = "http://www.baidu.com/"; 

$snoopy-&gt;cookies["SessionID"] = 238472834723489l;
$snoopy-&gt;cookies["favoriteColor"] = "RED"; 

$snoopy-&gt;rawheaders["Pragma"] = "no-cache"; 

$snoopy-&gt;maxredirs = 2;
$snoopy-&gt;offsiteok = false;
$snoopy-&gt;expandlinks = false; 

$snoopy-&gt;user = "joe";
$snoopy-&gt;pass = "bloe"; 

if($snoopy-&gt;fetchtext("http://www.baidu.com"))
{
echo " ".htmlspecialchars($snoopy-&gt;results)."n";

}

else

echo "error fetching document: ".$snoopy-&gt;error."n";</pre>
<p>[/codesyntax]</code><code lang="php"><br />
</code></div>
<p>snoopy采集示例<br />
<code lang="php"><br />
&lt; ?php<br />
//采集phpchina<br />
set_time_limit(0);<br />
require_once("Snoopy.class.php");<br />
$snoopy=new Snoopy();<br />
//登陆论坛<br />
$submit_url = "http://www.phpchina.com/bbs/logging.php?action=login";<br />
$submit_vars["loginmode"] = "normal";<br />
$submit_vars["styleid"] = "1";<br />
$submit_vars["cookietime"] = "315360000";<br />
$submit_vars["loginfield"] = "username";<br />
$submit_vars["username"] = "***"; //你的用户名<br />
$submit_vars["password"] = "*****"; //你的密码<br />
$submit_vars["questionid"] = "0";<br />
$submit_vars["answer"] = "";<br />
$submit_vars["loginsubmit"] = "提 交";<br />
$snoopy-&gt;submit($submit_url,$submit_vars);<br />
if ($snoopy-&gt;results)<br />
{<br />
//获取连接地址<br />
$snoopy-&gt;fetchlinks("http://www.phpchina.com/bbs");<br />
$url=array();<br />
$url=$snoopy-&gt;results;<br />
//print_r($url);<br />
foreach ($url as $key=&gt;$value)<br />
{<br />
//匹配http://www.phpchina.com/bbs/forumdisplay.php?fid=156&amp;sid=VfcqTR地址即论坛板块地址<br />
if (!preg_match("/^(http://www.phpchina.com/bbs/forumdisplay.php?fid=)[0-9]*&amp;sid=[a-zA-Z]{6}/i",$value))<br />
{<br />
unset($url[$key]);<br />
}<br />
}<br />
//print_r($url);<br />
//获取到板块数组$url，循环访问，此处获取第一个模块第一页的数据<br />
$i=0;<br />
foreach ($url as $key=&gt;$value)<br />
{<br />
if ($i&gt;=1)<br />
{<br />
//测试限制<br />
break;<br />
}<br />
else<br />
{<br />
//访问该模块，提取帖子的连接地址，正式访问里需要提取帖子分页的数据，然后根据分页数据提取帖子数据<br />
$snoopy=new Snoopy();<br />
$snoopy-&gt;fetchlinks($value);<br />
$tie=array();<br />
$tie[$i]=$snoopy-&gt;results;<br />
//print_r($tie);<br />
//转换数组<br />
foreach ($tie[$i] as $key=&gt;$value)<br />
{<br />
//匹配http://www.phpchina.com/bbs/viewthread.php?tid=68127&amp;extra=page%3D1&amp;page=1&amp;sid=iBLZfK<br />
if (!preg_match("/^(http://www.phpchina.com/bbs/viewthread.php?tid=)[0-9]*&amp;extra=page%3D1&amp;page=[0-9]*&amp;sid=[a-zA-Z]{6}/i",$value))<br />
{<br />
unset($tie[$i][$key]);<br />
}<br />
}<br />
//print_r($tie[$i]);<br />
//归类数组，将同一个帖子不同页面的内容放一个数组里<br />
$left='';//连接左边公用地址<br />
$j=0;<br />
$page=array();<br />
foreach ($tie[$i] as $key=&gt;$value)<br />
{<br />
$left=substr($value,0,52);<br />
$m=0;<br />
foreach ($tie[$i] as $pkey=&gt;$pvalue)<br />
{<br />
//重组数组<br />
if (substr($pvalue,0,52)==$left)<br />
{<br />
$page[$j][$m]=$pvalue;<br />
$m++;<br />
}<br />
}<br />
$j++;<br />
}<br />
//去除重复项开始<br />
//$page=array_unique($page);只能用于一维数组<br />
$paget[0]=$page[0];<br />
$nums=count($page);<br />
for ($n=1;$n&lt; $nums;$n++)<br />
{<br />
$paget[$n]=array_diff($page[$n],$page[$n-1]);<br />
}<br />
//去除多维数组重复值结束<br />
//去除数组空值<br />
unset($page);<br />
$page=array();//重新定义page数组<br />
$page=array_filter($paget);<br />
//print_r($page);<br />
$u=0;<br />
$title=array();<br />
$content=array();<br />
$temp='';<br />
$tt=array();<br />
foreach ($page as $key=&gt;$value)<br />
{<br />
//外围循环，针对一个帖子<br />
if (is_array($value))<br />
{<br />
foreach ($value as $k1=&gt;$v1)<br />
{<br />
//页内循环，针对一个帖子的N页<br />
$snoopy=new Snoopy();<br />
$snoopy-&gt;fetch($v1);<br />
$temp=$snoopy-&gt;results;<br />
//读取标题<br />
if (!preg_match_all("/</p>
<h2>(.*)&lt; /h2&gt;/i",$temp,$tt))<br />
{<br />
echo "no title";<br />
exit;<br />
}<br />
else<br />
{<br />
$title[$u]=$tt[1][1];<br />
}<br />
unset($tt);<br />
//读取内容<br />
if (!preg_match_all("/</p>
<div id="postmessage_[0-9]{1,8}" class="t_msgfont">(.*)&lt; /div&gt;/i",$temp,$tt))<br />
{<br />
print_r($tt);<br />
echo "no content1";<br />
exit;<br />
}<br />
else<br />
{<br />
foreach ($tt[1] as $c=&gt;$c2)<br />
{<br />
$content[$u].=$c2;<br />
}<br />
}<br />
}<br />
}<br />
else<br />
{<br />
//直接取页内容<br />
$snoopy=new Snoopy();<br />
$snoopy-&gt;fetch($value);<br />
$temp=$snoopy-&gt;results;<br />
//读取标题<br />
if (!preg_match_all("/</p>
<h2>(.*)&lt; /h2&gt;/i",$temp,$tt))<br />
{<br />
echo "no title";<br />
exit;<br />
}<br />
else<br />
{<br />
$title[$u]=$tt[1][1];<br />
}<br />
unset($tt);<br />
//读取内容<br />
if (!preg_match_all("/</p>
<div id="postmessage_[0-9]*" class="t_msgfont">(.*)&lt; /div&gt;/i",$temp,$tt))<br />
{<br />
echo "no content2";<br />
exit;<br />
}<br />
else<br />
{<br />
foreach ($tt[1] as $c=&gt;$c2)<br />
{<br />
$content[$u].=$c2;<br />
}<br />
}<br />
}<br />
$u++;<br />
}<br />
print_r($content);<br />
}<br />
$i++;<br />
}<br />
}<br />
else<br />
{<br />
echo "login failed";<br />
exit;<br />
}<br />
?&gt;</div>
</h2>
</div>
</h2>
<p> </p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/299.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP抓取远程网站数据的代码</title>
		<link>http://www.tisswb.com/archives/287.html</link>
		<comments>http://www.tisswb.com/archives/287.html#comments</comments>
		<pubDate>Sat, 07 Mar 2009 20:57:18 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php学习点滴]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=287</guid>
		<description><![CDATA[这几天开发一套新的采集系统，整理了一些这方面的资料：如何像搜索引擎那样去抓取别人网站的HTML代码,然后把代码收集整理成为自己有用的数据!今天就等我介绍一些简单例子吧.
Ⅰ.抓取远程网页标题的例子:

< ?php
/*
+-------------------------------------------------------------
+抓取网页标题的代码,直接拷贝本代码片段,另存为.php文件执行即可.
+-------------------------------------------------------------
*/
error_reporting(7);
<span class="readmore"><a href="http://www.tisswb.com/archives/287.html" title="PHP抓取远程网站数据的代码" target="_blank">阅读全文——共1792字</a></span>]]></description>
			<content:encoded><![CDATA[<p>这几天开发一套新的采集系统，整理了一些这方面的资料：如何像搜索引擎那样去抓取别人网站的HTML代码,然后把代码收集整理成为自己有用的数据!今天就等我介绍一些简单例子吧.</p>
<p><strong>Ⅰ.抓取远程网页标题的例子:</strong></p>
<p><code lang="php" linenum="on"><br />
< ?php<br />
/*<br />
+-------------------------------------------------------------<br />
+抓取网页标题的代码,直接拷贝本代码片段,另存为.php文件执行即可.<br />
+-------------------------------------------------------------<br />
*/<br />
error_reporting(7);<br />
$file = fopen ("http://www.dnsing.com/", "r");<br />
if (!$file) {<br />
echo "<font color=red>Unable to open remote file.n";<br />
exit;<br />
}<br />
while (!feof ($file)) {<br />
$line = fgets ($file, 1024);<br />
if (eregi ("", $line, $out)) {<br />
$title = $out[1];<br />
echo "".$title."";<br />
break;<br />
}<br />
}<br />
fclose($file); </p>
<p>//End<br />
?><br />
</code></p>
<p><strong>Ⅱ.抓取远程网页HTML代码的例子:</strong></p>
<p><code lang="php" linenum="on"><br />
< ? php<br />
/*<br />
+----------------<br />
+DNSing Sprider<br />
+----------------<br />
*/</p>
<p>$fp = fsockopen("www.dnsing.com", 80, $errno, $errstr, 30);<br />
if (!$fp) {<br />
   echo "$errstr ($errno)<br/>n";<br />
} else {<br />
   $out = "GET / HTTP/1.1rn";<br />
   $out .= "Host: www.dnsing.com rn";<br />
   $out .= "Connection: Close rnrn";<br />
   fputs($fp, $out);<br />
   while (!feof($fp)) {<br />
     echo fgets($fp, 128);<br />
   }<br />
   fclose($fp);<br />
}<br />
//End<br />
?></code></p>
<p>以上两个代码片段都直接Copy回去运行就知道效果了,上面的例子只是抓取网页数据的雏形,要使其更适合自己的使用,情况有各异.所以,在此各位程序爱好者自己好好研究一下吧.</p>
<p>===============================</p>
<p>稍微有点意义的函数是：get_content_by_socket(), get_url(), get_content_url(), get_content_object 几个函数，也许能够给你点什么想法。</p>
<p><code lang="php" linenum="on"><br />
< ?php </p>
<p>//获取所有内容url保存到文件<br />
function get_index($save_file, $prefix="index_"){<br />
     $count = 68;<br />
     $i = 1;<br />
     if (file_exists($save_file)) @unlink($save_file);<br />
     $fp = fopen($save_file, "a+") or die("Open ". $save_file ." failed");<br />
     while($i<$count){<br />
         $url = $prefix . $i .".htm";<br />
         echo "Get ". $url ."...";<br />
         $url_str = get_content_url(get_url($url));<br />
         echo " OKn";<br />
         fwrite($fp, $url_str);<br />
         ++$i;<br />
     }<br />
     fclose($fp);<br />
} </p>
<p>//获取目标多媒体对象<br />
function get_object($url_file, $save_file, $split="|--:**:--|"){<br />
     if (!file_exists($url_file)) die($url_file ." not exist");<br />
     $file_arr = file($url_file);<br />
     if (!is_array($file_arr) || empty($file_arr)) die($url_file ." not content");<br />
     $url_arr = array_unique($file_arr);<br />
     if (file_exists($save_file)) @unlink($save_file);<br />
     $fp = fopen($save_file, "a+") or die("Open save file ". $save_file ." failed");<br />
     foreach($url_arr as $url){<br />
         if (empty($url)) continue;<br />
         echo "Get ". $url ."...";<br />
         $html_str = get_url($url);<br />
         echo $html_str;<br />
         echo $url;<br />
         exit;<br />
         $obj_str = get_content_object($html_str);<br />
         echo " OKn";<br />
         fwrite($fp, $obj_str);<br />
     }<br />
     fclose($fp);<br />
} </p>
<p>//遍历目录获取文件内容<br />
function get_dir($save_file, $dir){<br />
     $dp = opendir($dir);<br />
     if (file_exists($save_file)) @unlink($save_file);<br />
     $fp = fopen($save_file, "a+") or die("Open save file ". $save_file ." failed");<br />
     while(($file = readdir($dp)) != false){<br />
         if ($file!="." &#038;&#038; $file!=".."){<br />
             echo "Read file ". $file ."...";<br />
             $file_content = file_get_contents($dir . $file);<br />
             $obj_str = get_content_object($file_content);<br />
             echo " OKn";<br />
             fwrite($fp, $obj_str);<br />
         }<br />
     }<br />
     fclose($fp);<br />
} </p>
<p>//获取指定url内容<br />
function get_url($url){<br />
     $reg = '/^http://[^/].+$/';<br />
     if (!preg_match($reg, $url)) die($url ." invalid");<br />
     $fp = fopen($url, "r") or die("Open url: ". $url ." failed.");<br />
     while($fc = fread($fp, 8192)){<br />
         $content .= $fc;<br />
     }<br />
     fclose($fp);<br />
     if (empty($content)){<br />
         die("Get url: ". $url ." content failed.");<br />
     }<br />
     return $content;<br />
} </p>
<p>//使用socket获取指定网页<br />
function get_content_by_socket($url, $host){<br />
     $fp = fsockopen($host, 80) or die("Open ". $url ." failed");<br />
     $header = "GET /".$url ." HTTP/1.1rn";<br />
     $header .= "Accept: */*rn";<br />
     $header .= "Accept-Language: zh-cnrn";<br />
     $header .= "Accept-Encoding: gzip, deflatern";<br />
     $header .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; InfoPath.1; .NET CLR 2.0.50727)rn";<br />
     $header .= "Host: ". $host ."rn";<br />
     $header .= "Connection: Keep-Alivern";<br />
     //$header .= "Cookie: cnzz02=2; rtime=1; ltime=1148456424859; cnzz_eid=56601755-rnrn";<br />
     $header .= "Connection: Closernrn"; </p>
<p>     fwrite($fp, $header);<br />
     while (!feof($fp)) {<br />
         $contents .= fgets($fp, 8192);<br />
     }<br />
     fclose($fp);<br />
     return $contents;<br />
} </p>
<p>//获取指定内容里的url<br />
function get_content_url($host_url, $file_contents){ </p>
<p>     //$reg = '/^(#|javascript.*?|ftp://.+|http://.+|.*?href.*?|play.*?|index.*?|.*?asp)+$/i';<br />
     //$reg = '/^(down.*?.html|d+_d+.htm.*?)$/i';<br />
     $rex = "/([hH][rR][eE][Ff])s*=s*['"]*([^>'"s]+)["'>]*s*/i";<br />
     $reg = '/^(down.*?.html)$/i';<br />
     preg_match_all ($rex, $file_contents, $r);<br />
     $result = ""; //array();<br />
     foreach($r as $c){<br />
         if (is_array($c)){<br />
             foreach($c as $d){<br />
                 if (preg_match($reg, $d)){ $result .= $host_url . $d."n"; }<br />
             }<br />
         }<br />
     }<br />
     return $result;<br />
} </p>
<p>//获取指定内容中的多媒体文件<br />
function get_content_object($str, $split="|--:**:--|"){<br />
     $regx = "/hrefs*=s*['"]*([^>'"s]+)["'>]*s*(<b>.*?< /b>)/i";<br />
     preg_match_all($regx, $str, $result); </p>
<p>     if (count($result) == 3){<br />
         $result[2] = str_replace("</b><b>多媒体： ", "", $result[2]);<br />
         $result[2] = str_replace("</b>", "", $result[2]);<br />
         $result = $result[1][0] . $split .$result[2][0] . "n";<br />
     }<br />
     return $result;<br />
} </p>
<p>?> </code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/287.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php小偷程序原理分析</title>
		<link>http://www.tisswb.com/archives/284.html</link>
		<comments>http://www.tisswb.com/archives/284.html#comments</comments>
		<pubDate>Sat, 07 Mar 2009 20:51:59 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php学习点滴]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=284</guid>
		<description><![CDATA[拿华军软件开刀,经过今天的教程以后,我相信大家都能偷.
当然,你想偷别的站也是一个道理.关键是方法.
我们打开华军软件园主站地址:
http://www.onlinedown.net/index.htm
当打开完成以后,点 查看&#8211;查看源文件
系统会用记事本显示出来首页的HTML代码.
/*
&#60;title&#62;华军软件园——共享软件发布-下载-学习-研究-交流之园(推荐用1024*768)&#60;/title&#62;
*/
看见这一行没?这就是标题.
<span class="readmore"><a href="http://www.tisswb.com/archives/284.html" title="php小偷程序原理分析" target="_blank">阅读全文——共10526字</a></span>]]></description>
			<content:encoded><![CDATA[<p>拿华军软件开刀,经过今天的教程以后,我相信大家都能偷.<br />
当然,你想偷别的站也是一个道理.关键是方法.<br />
我们打开华军软件园主站地址:<br />
<a href="http://www.onlinedown.net/index.htm">http://www.onlinedown.net/index.htm</a></p>
<p>当打开完成以后,点 查看&#8211;查看源文件<br />
系统会用记事本显示出来首页的HTML代码.</p>
<p>/*<br />
&lt;title&gt;华军软件园——共享软件发布-下载-学习-研究-交流之园(推荐用1024*768)&lt;/title&gt;<br />
*/<br />
看见这一行没?这就是标题.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
写小偷需要能看懂HTML才行哦?如果你一点HTML都看不懂的话,那就学起来有难度.<br />
现在大家从HTML中,找出华军软件园首页的<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
软件总数:30738 更新:287<br />
国产软件:160国外软件:113<br />
汉化补丁:13 数码软件:1<br />
杀毒快报:10 资讯中心:42<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
以上信息从HTML代码从 哪里开始.<br />
是单独表格还是在表格内的行,或者列.<br />
不会也没关系,看多了就会了.如果你不会以后想成为神偷就有难度,所以现在开始就得学习了.</p>
<p>好了,讲了这么多,就是告诉大家,小偷就是用ASP,PHP或者其他语言在程序中打开并且处理这些HTML<br />
拿PHP讲<br />
&lt;?php<br />
$files=&#8221;http://www.onlinedown.net/index.htm&#8221;;<br />
$fp=fopen($files,&#8221;a&#8221;);<br />
&#8230;..<br />
&#8230;&#8230;<br />
?&gt;<br />
把打开的HTML代码进行切割,更换.<br />
比如刚才叫大家找的.下面的信息<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
软件总数:30738 更新:287<br />
国产软件:160国外软件:113<br />
汉化补丁:13 数码软件:1<br />
杀毒快报:10 资讯中心:42<br />
&#8212;&#8212;&#8212;&#8212;&#8211;<br />
PHP就是处理这个index.htm<br />
把你要的信息切割处理.简单的这么讲<br />
&#8211;<br />
首页更新 = 从index.htm中切割出首页更新内容<br />
&#8211;<br />
然后在你要显示的地方输出,就显示了上面内容.</p>
<p>其他内容也是一样处理.<br />
处理原理就是这样.所以说是一直自动更新.<br />
按照你的办法切割着首页.它首页内容变新了,当访问你小偷的时候,你切割出来的内容是他的内容,所以是同步时时的内容.</p>
<p>今天就讲这么多,就弄明白原理,知道怎么回事就可以,别往深处想.如果你看不懂HTML的话,应该花几个小时看看了.以后要用.<br />
对自己要有信心,其实每个人都很聪明的.知识是慢慢积累的.<br />
我相信经过我几天的教程,到最后你能写出你自己的小偷来!</p>
<p>____________________________________________________________________________________________</p>
<p>今天教第二天.<br />
有个朋友说的好,其实教功夫也是变相的教你怎么杀人,可是不说出来.<br />
所以这个教程从下一篇开始就改个名字<br />
叫&lt;远程操作对方数据程序&gt;有点土比小偷好听<br />
第二天.<br />
教几个函数给大家.<br />
1 读取判断函数<br />
2 更新cache函数<br />
3 写入文件函数<br />
4 切割字符函数<br />
5 读取字符函数<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
在我们想写之前我们先要做好准备,构思一下怎么去写.<br />
制作前构思1<br />
我们打开华军首页<br />
[url]http://www.onlinedown.net/[/url]<br />
经过我们统计,是不是发现它的连接有个很相同的规则?<br />
1 根目录的index.htm文件<br />
2 soft文件夹的 1.htm &#8230;&#8230;.30000.htm<br />
3 sort文件夹的 1_1.htm   200_1.htm<br />
4 a-z文件夹 1.htm &#8230;.200.htm<br />
到此我们可以想好一个打开函数,不是根目录 就是文件夹/名字<br />
只有2中可能.<br />
制作前构思2<br />
为了让速度更快,我们最好把内容读过来存储起来.<br />
1 减少了对对方站点的请求.<br />
2 提供了速度.<br />
这里我们判断这个文件写入的时间为准 我们自己设置一个时间<br />
当写入时间 和现在的时间比一下,如果在我们的设置时间内的话.就是可以.<br />
如果不在比如<br />
文件写入时间 2004年5月18好 06:00 我们现在时间是2004年5月19号 18:00<br />
我们设置时间是1个小时<br />
当再次请求这个文件的时候 他发现已经过期了.就会重新向对方请求一次并且存入.<br />
制作前构思3<br />
为了以后频繁的操作简单话,把固定的操作写进一个函数.<br />
切割字符.<br />
一般切割就是 从第一个位置   切割到第二个位置 然后取中间部分<br />
比如:<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;演示站点&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
从&lt;title&gt;开始切割到&lt;/title&gt;<br />
那切割出来的 就是 &#8220;演示站点&#8221;4个字<br />
如果说,可以找到   几个 &lt;title&gt;怎么办?程序会从第一处开始切割<br />
到这里构思差不多..<br />
程序要干净明了才行,不要这一个文件不知道什么,那一个文件不知道哪来.<br />
所以,如果你以后有做大站的机会的话,文件夹,文件一定要写的清楚,分的清楚.<br />
既然明白了构思,我们就开始动手做了.<br />
建立我们第一个PHP文件:<br />
你可以用记事本,可以用Dreamweaver也可以用专用PHP编辑软件<br />
取名字为 commom.php<br />
内容为<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
&lt;?php<br />
include &#8216;./config.php&#8217;;<br />
include &#8216;./global.php&#8217;;<br />
?&gt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
这个文件有什么用?就是在以后操作中直接 inclue 这个文件就可以用到所有的函数啊什么的<br />
然后config.php是设置 URL 刷新时间 等等<br />
global.php是 所有函数的文件<br />
也就是今天要给教给大家的!<br />
第一个个函数 open<br />
&#8212;&#8212;&#8212;&#8212;-<br />
function open($file,$type=&#8221;){<br />
         global $fromurl,$referer;<br />
         $cachename=$file;<br />
                 if($type){<br />
                         $file=$fromurl.&#8217;/&#8217;.$type.&#8217;/&#8217;.$file;<br />
                 }else{<br />
                         $file=$fromurl.$file;<br />
                 }</p>
<p>                <br />
                <br />
                <br />
                         if($open=file($file)){<br />
                                         $count=count($open);<br />
                                         for($i=0;$i&lt;$count;$i++){<br />
                                                 $theget.=$open[$i];</p>
<p>                                         }<br />
                                        <br />
                                 }else{<br />
                                         die(&#8216;请求过多，超时，请刷新&#8217;);<br />
                                 }<br />
                <br />
                <br />
         return $theget;</p>
<p>}<br />
&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
解释过了,连接地址就2中请求,根目录,和 文件夹/名字<br />
函数怎么用法等等,不多说了.建议大家下载译本PHP中文手册看看.<br />
第二个函数<br />
根据设置时间更新cache目录文件函数 update<br />
&#8212;&#8212;&#8212;&#8212;&#8212;<br />
function update($file,$type=&#8221;){<br />
         global $timestamp,$flush;<br />
         if(!file_exists(&#8220;cache/$file&#8221;)){<br />
                 if($type){<br />
                         $data=open($file,$type);<br />
                 }else{<br />
                         $data=open($file);<br />
                 }<br />
                <br />
                 writetofile(&#8220;cache/$file&#8221;,$data);<br />
         }else{<br />
                 $lastflesh=@filemtime(&#8220;cache/$file&#8221;);<br />
                <br />
        <br />
        <br />
                 if($lastflesh + ($flush * 60) &lt; $timestamp ){<br />
                         if($type){<br />
                                 $data=open($file,$type);<br />
                         }else{<br />
                                 $data=open($file);<br />
                         }<br />
                         writetofile(&#8220;cache/$file&#8221;,$data);<br />
                 }<br />
         }</p>
<p>}<br />
&#8212;&#8212;&#8211;<br />
简单解释<br />
$data=open($file,$type);就是用到上面的 open函数了<br />
如果我们用 udate(&#8220;index.htm&#8221;);<br />
那不就是用到了 update函数吗? 明白吗?<br />
上面出现了writetofile函数 下面是代码<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
function writetofile($file_name,$data,$method=&#8221;w&#8221;) {<br />
         if($filenum=fopen($file_name,$method)){<br />
                 flock($filenum,LOCK_EX);<br />
                 $file_data=fwrite($filenum,$data);<br />
                 fclose($filenum);<br />
                 return $file_data;<br />
         }else{<br />
                 return false;<br />
         }<br />
}&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
切割字符函数<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
function cut($file,$from,$end){</p>
<p>         $message=explode($from,$file);<br />
         $message=explode($end,$message[1]);<br />
return         $message[0];<br />
}<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
读取函数<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
function readfromfile($file_name) {<br />
         if($filenum=fopen($file_name,&#8221;r&#8221;)){<br />
                 flock($filenum,LOCK_SH);<br />
                 $file_data=fread($filenum,filesize($file_name));<br />
                 fclose($filenum);<br />
                 return $file_data;<br />
         }else{<br />
                 return false;<br />
         }<br />
        <br />
}<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
把所有函数写成一个文件 保存起来 取名字叫 global.php<br />
内容如下:<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
&lt;?php<br />
function open($file,$type=&#8221;){<br />
         global $fromurl,$referer;<br />
         $cachename=$file;<br />
                 if($type){<br />
                         $file=$fromurl.&#8217;/&#8217;.$type.&#8217;/&#8217;.$file;<br />
                 }else{<br />
                         $file=$fromurl.$file;<br />
                 }</p>
<p>                <br />
                <br />
                <br />
                         if($open=file($file)){<br />
                                         $count=count($open);<br />
                                         for($i=0;$i&lt;$count;$i++){<br />
                                                 $theget.=$open[$i];</p>
<p>                                         }<br />
                                        <br />
                                 }else{<br />
                                         die(&#8216;请求过多，超时，请刷新&#8217;);<br />
                                 }<br />
                <br />
                <br />
         return $theget;</p>
<p>}</p>
<p>function update($file,$type=&#8221;){<br />
//更新cache中的文件<br />
         global $timestamp,$flush;<br />
         if(!file_exists(&#8220;cache/$file&#8221;)){<br />
                 if($type){<br />
                         $data=open($file,$type);<br />
                 }else{<br />
                         $data=open($file);<br />
                 }<br />
                <br />
                 writetofile(&#8220;cache/$file&#8221;,$data);<br />
         }else{<br />
                 $lastflesh=@filemtime(&#8220;cache/$file&#8221;);<br />
                <br />
        <br />
        <br />
                 if($lastflesh + ($flush * 60) &lt; $timestamp ){<br />
                         if($type){<br />
                                 $data=open($file,$type);<br />
                         }else{<br />
                                 $data=open($file);<br />
                         }<br />
                         writetofile(&#8220;cache/$file&#8221;,$data);<br />
                 }<br />
         }</p>
<p>}<br />
function readfromfile($file_name) {<br />
         if($filenum=fopen($file_name,&#8221;r&#8221;)){<br />
                 flock($filenum,LOCK_SH);<br />
                 $file_data=fread($filenum,filesize($file_name));<br />
                 fclose($filenum);<br />
                 return $file_data;<br />
         }else{<br />
                 return false;<br />
         }<br />
        <br />
}</p>
<p>function writetofile($file_name,$data,$method=&#8221;w&#8221;) {<br />
         if($filenum=fopen($file_name,$method)){<br />
                 flock($filenum,LOCK_EX);<br />
                 $file_data=fwrite($filenum,$data);<br />
                 fclose($filenum);<br />
                 return $file_data;<br />
         }else{<br />
                 return false;<br />
         }<br />
}<br />
function cut($file,$from,$end){</p>
<p>         $message=explode($from,$file);<br />
         $message=explode($end,$message[1]);<br />
return         $message[0];<br />
}<br />
function updatecache($file,$cache=&#8221;){<br />
         global $timestamp,$flush;<br />
         if(!file_exists($file)){<br />
                 writetofile($file,$cache);<br />
                 $return=$cache;<br />
         }elseif(@filemtime($file) &lt; $timestamp &#8211; ($flush * 60)){<br />
                 writetofile($file,$cache);<br />
                 $return=$cache;<br />
         }else{<br />
                 $return=readfromfile($file);        <br />
         }<br />
         return $return;<br />
}<br />
?&gt;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
其中有几个变量在config.php中设置一下<br />
我们建立config.php文件 内容如下:<br />
&lt;?php<br />
$fromurl = &#8220;http://www.onlinedown.net/&#8221;;<br />
$flush=&#8221;120&#8243;;//update函数中自动同步更新时间<br />
?&gt;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
现在位置我们有了3个文件了 commom.php config.php global.php<br />
有了3个文件 程序总体完成了.接下来如何去偷呢?<br />
心急的人可以先试试<br />
建立一个index.php文件 就是首页<br />
你先做好模板 的样子<br />
HTML先做好.<br />
然后在<br />
&lt;html&gt;<br />
&#8230;&#8230;..<br />
&#8230;&#8230;..<br />
&lt;/html&gt;<br />
的上方插入PHP代码<br />
如下:<br />
&lt;?php<br />
require &#8216;./commom.php&#8217;;<br />
update(&#8220;index.htm&#8221;);<br />
$file=readfromfile(&#8220;cache/index.htm&#8221;);<br />
$gwrj = cut($file,&#8221;&lt;TD width=&#8221;307&#8243; height=&#8221;118&#8243;&gt;&#8221;,&#8221;&lt;/TD&gt;&#8221;);<br />
?&gt;<br />
&lt;html&gt;<br />
&#8230;&#8230;.<br />
&#8230;&#8230;<br />
&#8230;&#8230;.<br />
&lt;/html&gt;<br />
在你想要插入的地方插入&lt;?php echo $gwrj; ?&gt;<br />
就是从首页中切割出来的国外软件<br />
自己试试</p>
<p>___________________________________________________________________________________________</p>
<p>今天我们教,偷取首页.不同的首页需要不同的偷法,主要是分析HTML代码.函数以及方法前面2天介绍的很清楚了.今天我们在实践中讲解和使用.</p>
<p>还是拿华军软件园开刀.<br />
<a href="http://www.onlinedown.net/index.htm">http://www.onlinedown.net/index.htm</a><br />
用Dreamweaver新建一个index.php的页子.<br />
注意:<br />
先做好你要的首页模板,然后开始偷首页.由于考虑到对初学者的教程.所以先把模板和PHP处理代码放在同一个网页中.<br />
以后教大家HTML和PHP的分离.</p>
<p>模板建立好以后,我们就开偷.<br />
在&lt;html&gt;<br />
的上方插入PHP代码,如下形式:<br />
&lt;?<br />
require &#8216;./commom.php&#8217;;<br />
update(&#8220;index.htm&#8221;);<br />
$file=readfromfile(&#8220;cache/index.htm&#8221;);</p>
<p>?&gt;<br />
解释<br />
require &#8216;./commom.php&#8217;//引入commom.php文件<br />
update(&#8220;index.htm&#8221;)//读取写入index.htm网页<br />
$file=readfromfile(&#8220;cache/index.htm&#8221;)//从本地文件夹cache中读取index.htm<br />
这里的$file是一个变量,你可以随便取名.也可以叫它 $html<br />
但是后面用到的时候要统一.</p>
<p>上面代码,没有处理任何东西,也没有输出任何的东西.如果说输出$file的话,那么就是index.htm的所有html代码.<br />
下面就开始到index.htm中拿我们想要的东东.</p>
<p>1 拿国外软件更新的代码.<br />
大家可以取一个变量名为 $gwrj    //国外软件 名字随便取<br />
怎么从这个index.htm拿出这个我们想要的国外软件呢?这里拿出我们上一节讲过的cut函数<br />
$gwrj = cut($file,&#8221;&lt;TD width=&#8221;307&#8243; height=&#8221;118&#8243;&gt;&#8221;,&#8221;&lt;/TD&gt;&#8221;);<br />
解释<br />
$xxx = cut($file,&#8221;$first&#8221;,&#8221;$end&#8221;);<br />
如何工作的呢?就是把$file(index.htm)从$first处切割取下面部分,在切割$end取上面部分.<br />
比如说:<br />
$file = &#8220;111222333444&#8243;;<br />
$xxx = cut($file,&#8221;1&#8243;,&#8221;3&#8243;);//结果是11222 这样的解释应该明白吧?<br />
注意:<br />
&#8220;&lt;TD width=&#8221;307&#8243; height=&#8221;118&#8243;&gt;&#8221;<br />
在&#8221; &#8220;内的内容 如果也有 &#8221; 的话,需要在前面加<br />
例子<br />
&#8220;&lt;TD width=&#8221;307&#8243; height=&#8221;118&#8243;&gt;&#8221;<br />
成为<br />
&#8220;&lt;TD width=&#8221;307&#8243; height=&#8221;118&#8243;&gt;&#8221;<br />
下面这段代码就是成功偷取了国外软件:<br />
&lt;?<br />
require &#8216;./commom.php&#8217;;<br />
update(&#8220;index.htm&#8221;);<br />
$file=readfromfile(&#8220;cache/index.htm&#8221;);<br />
$gwrj = cut($file,&#8221;&lt;TD width=&#8221;307&#8243; height=&#8221;118&#8243;&gt;&#8221;,&#8221;&lt;/TD&gt;&#8221;);<br />
?&gt;<br />
然后在你的html模板中,在需要显示的地方插入代码<br />
&lt;? echo $gwrj; ?&gt;</p>
<p>其他偷取也一样.<br />
注意:<br />
这里拿出来的HTML需要更换为自己的代码,可以总的更换,也可以一个一个更换.<br />
我们讲单独更换代码就是:<br />
$gwrj = cut($file,&#8221;&lt;TD width=&#8221;307&#8243; height=&#8221;118&#8243;&gt;&#8221;,&#8221;&lt;/TD&gt;&#8221;);<br />
$gwrj = str_replace(&#8220;soft/&#8221;,&#8221;soft.php?id=&#8221;,$gwrj);<br />
$gwrj = str_replace(&#8220;.htm&#8221;,&#8221;",$gwrj);<br />
解释:<br />
就是把偷过来的国外软件中的代码更换.<br />
原来的<br />
&lt;a target=_blank href=&#8221;soft/18204.htm&#8221;&gt;<br />
变为了现在的<br />
&lt;a target=_blank href=&#8221;soft.php?id=18204&#8243;&gt;</p>
<p>基本差不多了,多菜鸟讲来应该很详细咯.先做好首页模板,然后一个一个的挖出来你想要的东西.<br />
想一个问题.<br />
index.htm中,有很多分类资讯的,都是调用JS显示的内容,你怎么把它拿过来显示在你的首页中.<br />
希望大家偷的都很顺利.<br />
简单讲下分类的偷取.和偷取首页一样.代码如下:<br />
&lt;?<br />
require &#8216;./commom.php&#8217;;</p>
<p>if($soft){<br />
         update(&#8220;${soft}.htm&#8221;,&#8221;soft&#8221;);<br />
         $file=readfromfile(&#8220;cache/${soft}.htm&#8221;);<br />
}<br />
?&gt;<br />
soft.php<br />
其中$soft就是从前面传递过来的soft.php?id=1234<br />
如果传递过来1234<br />
那么就是更新读取update(&#8220;1234.html&#8221;,&#8221;soft&#8221;);</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/284.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP小偷原理实现及改进</title>
		<link>http://www.tisswb.com/archives/272.html</link>
		<comments>http://www.tisswb.com/archives/272.html#comments</comments>
		<pubDate>Sat, 07 Mar 2009 20:36:41 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php学习点滴]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=272</guid>
		<description><![CDATA[PHP小偷程序说白了就是让别人帮你维护你的网站，有点不劳而获的意思。至于这个东西到底是好是坏我们不评价了，还是研究一下程序要紧。
优点：通过PHP小偷我们可以借用别人网站上的信息而不用自己辛苦地去采集
缺点：需要把整页的HTML代码读取到本地,然后通过匹配获取到想要的信息再进行显示,这样大大影响网页的加载速度
改进：通过AJAX异步读取HTML代码,后台进行匹配获取到想要的信息,再显示到前台页面
预备知识：PHP,AJAX,正则表达式
关键字：file_get_contents()  fopen()  fwrite()  eregi()
前三个关键字都是关于PHP文件处理的函数,eregi()是关于正则表达式的函数
PHP小偷原理的实现
一、file_get_contents() fopen() fwrite() 的应用
咱们用华夏黑客牛刀小试吧,把主页的全部信息获取过来
<span class="readmore"><a href="http://www.tisswb.com/archives/272.html" title="PHP小偷原理实现及改进" target="_blank">阅读全文——共2032字</a></span>]]></description>
			<content:encoded><![CDATA[<p>PHP小偷程序说白了就是让别人帮你维护你的网站，有点不劳而获的意思。至于这个东西到底是好是坏我们不评价了，还是研究一下程序要紧。</p>
<p><strong>优点</strong>：通过PHP小偷我们可以借用别人网站上的信息而不用自己辛苦地去采集</p>
<p><strong>缺点</strong>：需要把整页的HTML代码读取到本地,然后通过匹配获取到想要的信息再进行显示,这样大大影响网页的加载速度</p>
<p><strong>改进</strong>：通过AJAX异步读取HTML代码,后台进行匹配获取到想要的信息,再显示到前台页面</p>
<p><strong>预备知识</strong>：PHP,AJAX,正则表达式</p>
<p><strong>关键字</strong>：file_get_contents()  fopen()  fwrite()  eregi()</p>
<p>前三个关键字都是关于PHP文件处理的函数,eregi()是关于正则表达式的函数</p>
<p>PHP小偷原理的实现</p>
<p>一、file_get_contents() fopen() fwrite() 的应用</p>
<p>咱们用华夏黑客牛刀小试吧,把主页的全部信息获取过来</p>
<p>建立一个PHP文件</p>
<p><code lang="php"><br />
&lt; ?php<br />
$url = 'http://www.77169.com/';<br />
//file_get_contents（）函数获取网页的html文档<br />
$file = file_get_contents ( $url );<br />
//建立一个新文件ImitationIndex.htm<br />
$newfile = fopen ( 'ImitationIndex.htm', 'w' );<br />
//把内容读取进去<br />
fwrite ( $newfile, $file );<br />
//关闭打开的文件<br />
fclose ( $newfile );<br />
?&gt;<br />
</code><br />
ImitationIndex.htm获取主页全部的HTML(保存好,以备下次使用)</p>
<p>二、eregi()函数的应用</p>
<p>通过eregi()获取里的内容</p>
<div><code lang="php"><br />
&lt; ?php<br />
$url = 'http://www.77169.com/';<br />
//file_get_contents（）函数获取网页的html文档<br />
$file = file_get_contents ( $url );<br />
//通过eregi()匹配获取想要的信息<br />
eregi ( '之间的内容</code></div>
<div><code lang="php">　　从上面的两个例子,已经知道PHP小偷的实现原理,从中也知道它的不足之处,但通过AJAX可以完善它,使它可以用于实践项目中</code></div>
<p><code lang="php">　　PHP小偷技术的实用和改进</p>
<p>　　目的:获取华夏黑客的最新资讯,并实时更新查看示例<br />
实际中可能只用到三个页面</p>
<p>　　showNews.php,Update.php,HackNews.htm</p>
<p>　　但为了能看到实时更新的效果,这里用到了模拟主页的页面ImitationIndex.htm</p>
<div><code lang="html"><br />
<!--<br />
body {<br />
background: #c60;<br />
}</div>
<div mce_tmp="1">a {<br />
color: #444;<br />
font: 12px Courier New;<br />
padding: 8px;<br />
}</div>
<div mce_tmp="1">a:hover {<br />
color: #f00<br />
}</div>
<div mce_tmp="1">#hei_content {<br />
width: 400px;<br />
background: #ccc;<br />
border: 2px solid #000;<br />
border-bottom: 5px solid #000;<br />
}<br />
--></div>
<p></code><code lang="html">&lt; ?php<br />
echo ('<br />
</code></p>
<div></div>
</div>
<p> </p>
<p></code><code lang="html"></p>
<div id="hei_content">');<br />
include ('HackNews.htm');<br />
echo ('');<br />
?&gt;<br />
<script type="text/javascript"><!--
window.onload=UpdateNews;
function GetXmlHttp()
{
var xmlhttp;
try
{
//IE7.0 ect
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}</p>
<p>catch(a)
{
try
{
//ie6.0 ect
xmlhttp=new ActiveXObject("Mscrosoft.XMLHTTP");
}
catch(b)
{
//非IE
xmlhttp=new XMLHttpRequest();
}
}
return xmlhttp;
}
function StateChange()
{
if(xmlhttp.readyState==4&#038;&#038;xmlhttp.status==200)
{
document.getElementById("hei_content").innerHTML=xmlhttp.responseText;
}
}
function UpdateNews()
{
xmlhttp=GetXmlHttp();
xmlhttp.onreadystatechange=StateChange;</p>
<p>var url='Update.php';
url=url+"?sid="+Math.random();
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
// --></script></div>
<p>showNews.php中的</p>
<div><code lang="php"><br />
echo('</code></div>
<p></code><code lang="php"></p>
<div id="hei_content">');<br />
include('HackNews.htm');<br />
echo('</div>
<p>');</p>
<p></code></p>
<p>　　HackNews.htm是已经缓存的文件,这样不用加载主页上的整个HTML再显示,这个工作留给AJAX</p>
<p>　　document.getElementById(&#8220;hei_content&#8221;).innerHTML=xmlhttp.responseText</p>
<p>　　xmlhttp.responseText就是加载更新后的内容</p>
<p>　　Update.php</p>
<div><code lang="html"><br />
&lt; ?php<br />
$url = 'ImitationIndex.htm';<br />
//file_get_contents（）函数获取网页的html文档<br />
$file = file_get_contents ( $url );<br />
//$regx为正则表达式的内容,用于匹配获取想要的信息<br />
$regx = '</code></div>
<p><code lang="html"></p>
<td colspan="3" height="100" background="http://hack.77169.com/20090220100422648.gif"> </td>
<p> (.*)<br />
&lt; /td&gt;<br />
&lt; /tr&gt;<br />
&lt; /table&gt;<br />
&lt; /td&gt;<br />
&lt; /tr&gt;</p>
<td colspan="3"> </td>
<p> <img src="" alt="" height="8" /> //eregi()获取匹配到的内容,赋值给数组变量$rg;<br />
eregi ( $regx, $file, $rg );<br />
//建立一个新文件HackNews.htm<br />
$newfile = fopen ( 'HackNews.htm', 'w' );<br />
//把内容读取进去<br />
fwrite ( $newfile, $rg [1] );<br />
fclose ( $newfile );<br />
//用iconv编码转换后,输出匹配的HTML内容<br />
$rg [1] = iconv ( 'gb2312', 'utf-8', $rg [1] );<br />
echo ($rg [1]);<br />
?/&gt; </p>
<p>　　Update.php是异步更新的后台页面</p>
<p></code></p>
<p>　　$newfile=fopen(&#8216;HackNews.htm&#8217;,'w&#8217;);</p>
<p>　　fwrite($newfile,$rg[1]);</p>
<p>　　把更新的内容重新保存在HackNews.htm中,下次在index.php中include时就直接调用这个页面</p>
<p>　　$url=&#8217;ImitationIndex.htm&#8217;在实际应用中应该是这样$url=&#8217;http://www.77169.com/&#8217;</p>
<p>　　但为了便于调试,建立一个ImitationIndex.htm模拟页面,如果对ImitationIndex.htm页面中最新资讯中的内容改改,就可以看到实时更新效果。</p>
<p>　　总结:通过AJAX改进的PHP小偷技术,在采集多个网站的大量信息下,页面的加载速度并不会受多大影响。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/272.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP采集程序中常用的函数</title>
		<link>http://www.tisswb.com/archives/259.html</link>
		<comments>http://www.tisswb.com/archives/259.html#comments</comments>
		<pubDate>Sat, 07 Mar 2009 19:52:41 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php学习点滴]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=259</guid>
		<description><![CDATA[网上找到的，给大家总结一下：

//获得当前的脚本网址
function get_php_url(){
        if(!empty($_SERVER["REQUEST_URI"])){
                $scriptName = $_SERVER["REQUEST_URI"];
                $nowurl = $scriptName;
        }else{
                $scriptName = $_SERVER["PHP_SELF"];
                if(empty($_SERVER["QUERY_STRING"])) $nowurl = $scriptName;
<span class="readmore"><a href="http://www.tisswb.com/archives/259.html" title="PHP采集程序中常用的函数" target="_blank">阅读全文——共2780字</a></span>]]></description>
			<content:encoded><![CDATA[<p>网上找到的，给大家总结一下：<br />
<code lang="php" linenum="on" download="phpcaiji_function.php"><br />
//获得当前的脚本网址<br />
function get_php_url(){<br />
        if(!empty($_SERVER["REQUEST_URI"])){<br />
                $scriptName = $_SERVER["REQUEST_URI"];<br />
                $nowurl = $scriptName;<br />
        }else{<br />
                $scriptName = $_SERVER["PHP_SELF"];<br />
                if(empty($_SERVER["QUERY_STRING"])) $nowurl = $scriptName;<br />
                else $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];<br />
        }<br />
        return $nowurl;<br />
}<br />
//把全角数字转为半角数字<br />
function GetAlabNum($fnum){<br />
        $nums = array("０","１","２","３","４","５","６","７","８","９");<br />
        $fnums = "0123456789";<br />
        for($i=0;$i< =9;$i++) $fnum = str_replace($nums[$i],$fnums[$i],$fnum);<br />
        $fnum = ereg_replace("[^0-9.]|^0{1,}","",$fnum);<br />
        if($fnum=="") $fnum=0;<br />
        return $fnum;<br />
}<br />
//去除HTML标记<br />
function Text2Html($txt){<br />
        $txt = str_replace("  ","　",$txt);<br />
        $txt = str_replace("<","<",$txt);<br />
        $txt = str_replace(">",">",$txt);<br />
        $txt = preg_replace("/[rn]{1,}/isU","<br />rn",$txt);<br />
        return $txt;<br />
}</p>
<p>//清除HTML标记<br />
function ClearHtml($str){<br />
        $str = str_replace('< ','<',$str);<br />
        $str = str_replace('>','>',$str);<br />
        return $str;<br />
}<br />
//相对路径转化成绝对路径<br />
function relative_to_absolute($content, $feed_url) {<br />
    preg_match('/(http|https|ftp):///', $feed_url, $protocol);<br />
    $server_url = preg_replace("/(http|https|ftp|news):///", "", $feed_url);<br />
    $server_url = preg_replace("//.*/", "", $server_url);</p>
<p>    if ($server_url == '') {<br />
        return $content;<br />
    }</p>
<p>    if (isset($protocol[0])) {<br />
        $new_content = preg_replace('/href="//', 'href="'.$protocol[0].$server_url.'/', $content);<br />
        $new_content = preg_replace('/src="//', 'src="'.$protocol[0].$server_url.'/', $new_content);<br />
    } else {<br />
        $new_content = $content;<br />
    }<br />
    return $new_content;<br />
}<br />
//取得所有链接<br />
function get_all_url($code){<br />
        preg_match_all('/<a s+href=["|']?([^>"' ]+)["|']?s*[^>]*>([^>]+)< /a>/i',$code,$arr);<br />
        return array('name'=>$arr[2],'url'=>$arr[1]);<br />
}</p>
<p>//获取指定标记中的内容<br />
function get_tag_data($str, $start, $end){<br />
        if ( $start == '' || $end == '' ){<br />
               return;<br />
        }<br />
        $str = explode($start, $str);<br />
        $str = explode($end, $str[1]);<br />
        return $str[0];<br />
}<br />
//HTML表格的每行转为CSV格式数组<br />
function get_tr_array($table) {<br />
        $table = preg_replace("'
<td [^>]*?>'si",'"',$table);<br />
        $table = str_replace("</td>
<p>",'",',$table);<br />
        $table = str_replace("","{tr}",$table);<br />
        //去掉 HTML 标记<br />
        $table = preg_replace("'< [/!]*?[^<>]*?>'si","",$table);<br />
        //去掉空白字符<br />
        $table = preg_replace("'([rn])[s]+'","",$table);<br />
        $table = str_replace(" ","",$table);<br />
        $table = str_replace(" ","",$table);</p>
<p>        $table = explode(",{tr}",$table);<br />
        array_pop($table);<br />
        return $table;<br />
}</p>
<p>//将HTML表格的每行每列转为数组，采集表格数据<br />
function get_td_array($table) {<br />
        $table = preg_replace("'<br />
<table [^>]*?>'si","",$table);<br />
        $table = preg_replace("'<br />
<tr [^>]*?>'si","",$table);<br />
        $table = preg_replace("'
<td [^>]*?>'si","",$table);<br />
        $table = str_replace("</td>
</tr>
<p>","{tr}",$table);<br />
        $table = str_replace("","{td}",$table);<br />
        //去掉 HTML 标记<br />
        $table = preg_replace("'< [/!]*?[^<>]*?>'si","",$table);<br />
        //去掉空白字符<br />
        $table = preg_replace("'([rn])[s]+'","",$table);<br />
        $table = str_replace(" ","",$table);<br />
        $table = str_replace(" ","",$table);</p>
<p>        $table = explode('{tr}', $table);<br />
        array_pop($table);<br />
        foreach ($table as $key=>$tr) {<br />
                $td = explode('{td}', $tr);<br />
                array_pop($td);<br />
            $td_array[] = $td;<br />
        }<br />
        return $td_array;<br />
}</p>
<p>//返回字符串中的所有单词 $distinct=true 去除重复<br />
function split_en_str($str,$distinct=true) {<br />
        preg_match_all('/([a-zA-Z]+)/',$str,$match);<br />
        if ($distinct == true) {<br />
                $match[1] = array_unique($match[1]);<br />
        }<br />
        sort($match[1]);<br />
        return $match[1];<br />
}<br />
</table>
<p></a></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/259.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP学习——获得URL信息的类</title>
		<link>http://www.tisswb.com/archives/255.html</link>
		<comments>http://www.tisswb.com/archives/255.html#comments</comments>
		<pubDate>Sat, 07 Mar 2009 19:32:10 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php学习点滴]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=255</guid>
		<description><![CDATA[获取URL信息的类
使用这个类，你能获得URL的如下信息：
- Host
- Path
- Statuscode (eg. 404,200, &#8230;)
- HTTP Version
- Server
- Content Type
- Date
- The whole header string of the URL
<span class="readmore"><a href="http://www.tisswb.com/archives/255.html" title="PHP学习——获得URL信息的类" target="_blank">阅读全文——共5315字</a></span>]]></description>
			<content:encoded><![CDATA[<p>获取URL信息的类<br />
使用这个类，你能获得URL的如下信息：<br />
- Host<br />
- Path<br />
- Statuscode (eg. 404,200, &#8230;)<br />
- HTTP Version<br />
- Server<br />
- Content Type<br />
- Date<br />
- The whole header string of the URL</p>
<p><code lang="php" linenum="on"><br />
< ?php<br />
/**<br />
 * Class for getting information about URL's<br />
 * @author Sven Wagener <[email]sven.wagener@intertribe.de[/email]><br />
 * @copyright Intertribe limited<br />
 * @PHP中文社区收集整理 [url]www.phpNet.cn[/url]<br />
 * @include Funktion:_include_<br />
 */<br />
class url {<br />
	var $url = "";<br />
	var $url_host;<br />
	var $url_path;<br />
	var $file = "";<br />
	var $code = "";<br />
	var $code_desc = "";<br />
	var $http_version = ""; // Variable for HTTP version<br />
	var $header_stream;<br />
	var $header_array;<br />
	var $timeout = "1";<br />
	/**<br />
	 * Constructor of class url<br />
	 * @param string $url the complete url<br />
	 * @desc Constructor of class url<br />
	 */<br />
	function url($url) {<br />
		$this->url = $url;<br />
		$url_array = parse_url ( $this->url );<br />
		$this->url_host = $url_array ['host'];<br />
		$this->url_path = $url_array ['path'];<br />
		if ($this->url_path == "") {<br />
			$this->url_path = "/";<br />
		}<br />
		$this->refresh_headerinfo ();<br />
	}<br />
	/**<br />
	 * Returns the whole url<br />
	 * @return string $url the whole url<br />
	 * @desc Returns the whole url<br />
	 */<br />
	function get_url() {<br />
		return $this->url;<br />
	}<br />
	/**<br />
	 * Returns the host of the url<br />
	 * @return string $url_host the host of the url<br />
	 * @desc Returns the host of the url<br />
	 */<br />
	function get_url_host() {<br />
		return $this->url_host;<br />
	}<br />
	/**<br />
	 * Returns the path of the url<br />
	 * @return string $url_path the path of the url<br />
	 * @desc Returns the path of the url<br />
	 */<br />
	function get_url_path() {<br />
		return $this->url_path;<br />
	}<br />
	/**<br />
	 * Returns the status code of the url<br />
	 * @return string $status_code the status code<br />
	 * @desc Returns the status code of the url<br />
	 */<br />
	function get_statuscode() {<br />
		return $this->code;<br />
	}<br />
	/**<br />
	 * Returns the status code description of the url<br />
	 * @return string $status_code_desc the status code description<br />
	 * @desc Returns the status code description of the url<br />
	 */<br />
	function get_statuscode_desc() {<br />
		return $this->code_desc;<br />
	}<br />
	/**<br />
	 * Returns the http version of the url by the returned headers of the server<br />
	 * @return string $http_version the http version<br />
	 * @desc Returns the http version of the url by the returned headers of the server<br />
	 */<br />
	function get_info_http_version() {<br />
		return $this->http_version;<br />
	}<br />
	/**<br />
	 * Returns the server type of the url's host by the returned headers of the server<br />
	 * @return string header_array['Server'] the server type<br />
	 * @desc Returns the server type of the url's host by the returned headers of the server<br />
	 */<br />
	function get_info_server() {<br />
		return $this->header_array ['Server'];<br />
	}<br />
	/**<br />
	 * Returns the date of the url's host by the returned headers of the server<br />
	 * @return string $header_array['Date'] the date<br />
	 * @desc Returns the date of the url's host by the returned headers of the server<br />
	 */<br />
	function get_info_date() {<br />
		return $this->header_array ['Date'];<br />
	}<br />
	/*<br />
function get_info_content_length(){<br />
return $this->header_array['Content-Length'];<br />
}<br />
*/<br />
	/**<br />
	 * Returns the content type by the returned headers of the server<br />
	 * @return string header_array['Content-Type'] the content type<br />
	 * @desc Returns the content type by the returned headers of the server<br />
	 */<br />
	function get_info_content_type() {<br />
		return $this->header_array ['Content-Type'];<br />
	}<br />
	/**<br />
	 * Returns the content of the url without the headers<br />
	 * @return string $content the content<br />
	 * @desc Returns the content of the url without the headers<br />
	 */<br />
	function get_content() {<br />
		// Get a web page into a string<br />
		$string = implode ( '', file ( $this->url ) );<br />
		return $string;<br />
	}<br />
	/**<br />
	 * Returns the whole header of url without content<br />
	 * @return string $header the header<br />
	 * @desc Returns the whole header of url without content<br />
	 */<br />
	function get_header_stream() {<br />
		return $this->header_stream;<br />
	}<br />
	/**<br />
	 * Returns the whole headers of the url in an array<br />
	 * @return array $header_array the headers in an array<br />
	 * @desc Returns the whole headers of the url in an array<br />
	 */<br />
	function get_headers() {<br />
		return $this->header_array;<br />
	}<br />
	/**<br />
	 * Refreshes the header information<br />
	 * @desc Refreshes the header information<br />
	 */<br />
	function refresh_headerinfo() {<br />
		// Open socket for connection via port 80 to put headers<br />
		$fp = fsockopen ( $this->url_host, 80, $errno, $errstr, 30 );<br />
		if (! $fp) {<br />
			// echo "$errstr ($errno)";<br />
			if ($errno == 0) {<br />
				$errstr = "Server Not Found";<br />
			}<br />
			$this->code = $errno;<br />
			$this->code_desc = $errstr;<br />
		} else {<br />
			$put_string = "GET " . $this->url_path . " HTTP/1.0rnHost: " . $this->url_host . "rnrn";<br />
			fputs ( $fp, $put_string );<br />
			@socket_set_timeout ( $fp, $this->timeout );<br />
			$stream = "";<br />
			$this->header_array = "";<br />
			$header_end = false;<br />
			// Getting header string and creating header array<br />
			$i = 0;<br />
			while ( ! feof ( $fp ) &#038;&#038; ! $header_end ) {<br />
				$line = fgets ( $fp, 128 );<br />
				if (strlen ( $line ) == 2) {<br />
					$header_end = true;<br />
				} else {<br />
					if ($i == 0) {<br />
						$line1 = $line;<br />
					}<br />
					$stream .= $line;<br />
					$splitted_line = split ( ":", $line );<br />
					$this->header_array [$splitted_line [0]] = $splitted_line [1];<br />
					$i ++;<br />
				}<br />
			}<br />
			fclose ( $fp );<br />
			$this->header_stream = $stream;<br />
			$splitted_stream = split ( " ", $line1 );<br />
			// Getting status code and description of the URL<br />
			$this->code = $splitted_stream [1];<br />
			$this->code_desc = $splitted_stream [2];<br />
			if (count ( $splitted_stream ) > 3) {<br />
				for($i = 3; $i < count ( $splitted_stream ); $i ++) {<br />
					$this->code_desc .= " " . $splitted_stream [$i];<br />
				}<br />
			}<br />
			// Cleaning up for n and r<br />
			$this->code_desc = preg_replace ( "[n]", "", $this->code_desc );<br />
			$this->code_desc = preg_replace ( "[r]", "", $this->code_desc );<br />
			// Getting Http Version<br />
			$http_array = split ( "/", $splitted_stream [0] );<br />
			$this->http_version = $http_array [1];<br />
		}<br />
	}<br />
	/**<br />
	 * Sets the timeout for getting header data from server<br />
	 * @param int $seconds time for timeout in seconds<br />
	 * @desc Sets the timeout for getting header data from server<br />
	 */<br />
	function set_timeout($seconds) {<br />
		$this->timeout = $seconds;<br />
	}<br />
}<br />
?><br />
</code></p>
<p>调用代码：<br />
<code lang="php" linenum="on"><br />
< ?php<br />
include ("url.class.php");<br />
$url = new url ( "[url]http://www.phpNet.cn/[/url]" );<br />
echo $url->get_header_stream ();<br />
$headers = $url->get_headers ();<br />
echo $headers ['Server'];<br />
echo $url->get_content ();<br />
echo "URL: <b>" . $url->get_url () . "</b><br />n";<br />
echo "URL Host: " . $url->get_url_host () . "<br />n";<br />
echo "URL Path: " . $url->get_url_path () . "<br />n<br />n";<br />
echo "Statuscode: " . $url->get_statuscode () . "<br />n";<br />
echo "Statuscode description: " . $url->get_statuscode_desc () . "<br />n";<br />
echo "HTTP Version: " . $url->get_info_http_version () . "<br />n";<br />
echo "Server: " . $url->get_info_server () . "<br />n";<br />
echo "Content Type: " . $url->get_info_content_type () . "<br />n";<br />
echo "Date: " . $url->get_info_date () . "<br />n<br />n";<br />
echo "WHOLE HEADERS:<br />n";<br />
echo $url->get_header_stream ();<br />
?> </code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/255.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Discuz 6.0, 6.1的在线人数极不准确的解决办法</title>
		<link>http://www.tisswb.com/archives/192.html</link>
		<comments>http://www.tisswb.com/archives/192.html#comments</comments>
		<pubDate>Fri, 07 Nov 2008 05:05:59 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[discuz]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=192</guid>
		<description><![CDATA[现在使用discuz6.0，6.1的人越来越多，有些人对模板进行了大规模的修改以后，发现在线统计用户数量的功能接近失效，与实际效果相差很大，我也是被这个问题困扰了有半年左右的时间，后台设置了一个遍，也没能够解决这个问题。最近还是不死心，继续检查程序和模板，同时也在网上搜索。
今天发现了一个帖子：说是这种情况的原因可能是模板footer.htm里缺少了一个触发函数：updatesession()。
具体的操作如下：
编辑fotter.htm，在里面添加进  {eval updatesession();}这么一句，触发一下session的相应机制。
我照做了，果然困扰我达半年左右的问题解决了，一个字爽，希望这个文章也能给大家有帮助。
方法来源：我是結他手‧音樂論壇。
]]></description>
			<content:encoded><![CDATA[<p>现在使用discuz6.0，6.1的人越来越多，有些人对模板进行了大规模的修改以后，发现在线统计用户数量的功能接近失效，与实际效果相差很大，我也是被这个问题困扰了有半年左右的时间，后台设置了一个遍，也没能够解决这个问题。最近还是不死心，继续检查程序和模板，同时也在网上搜索。</p>
<p>今天发现了一个帖子：说是这种情况的原因可能是模板footer.htm里缺少了一个触发函数：updatesession()。</p>
<p>具体的操作如下：</p>
<p><span style="color: #ff0000;">编辑fotter.htm，在里面添加进  {eval updatesession();}这么一句，触发一下session的相应机制。</span></p>
<p>我照做了，果然困扰我达半年左右的问题解决了，一个字爽，希望这个文章也能给大家有帮助。</p>
<p>方法来源：我是結他手‧音樂論壇。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/192.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php按指定大小生成不变形缩略图的函数</title>
		<link>http://www.tisswb.com/archives/171.html</link>
		<comments>http://www.tisswb.com/archives/171.html#comments</comments>
		<pubDate>Mon, 27 Oct 2008 08:39:02 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=171</guid>
		<description><![CDATA[今天需要写一个用php生成缩略图的函数，在网上转了转，发现了一个好人写的一段代码，感觉很标准，就拿来给大家分享分享这个按指定大小生成不变形缩略图的函数。
&#60;?php
function image_resize($f, $t, $tw, $th){
// 按指定大小生成缩略图，而且不变形，缩略图函数
// Cos.x 2007-9-5
        $temp = array(1=&#62;&#8217;gif&#8217;, 2=&#62;&#8217;jpeg&#8217;, 3=&#62;&#8217;png&#8217;);
        list($fw, $fh, $tmp) = getimagesize($f);
        if(!$temp[$tmp]){
                return false;
        }
<span class="readmore"><a href="http://www.tisswb.com/archives/171.html" title="php按指定大小生成不变形缩略图的函数" target="_blank">阅读全文——共664字</a></span>]]></description>
			<content:encoded><![CDATA[<p>今天需要写一个用php生成缩略图的函数，在网上转了转，发现了一个好人写的一段代码，感觉很标准，就拿来给大家分享分享这个按指定大小生成不变形缩略图的函数。</p>
<p>&lt;?php<br />
function image_resize($f, $t, $tw, $th){<br />
// 按指定大小生成缩略图，而且不变形，缩略图函数<br />
// Cos.x 2007-9-5<br />
        $temp = array(1=&gt;&#8217;gif&#8217;, 2=&gt;&#8217;jpeg&#8217;, 3=&gt;&#8217;png&#8217;);</p>
<p>        list($fw, $fh, $tmp) = getimagesize($f);</p>
<p>        if(!$temp[$tmp]){<br />
                return false;<br />
        }<br />
        $tmp = $temp[$tmp];<br />
        $infunc = &#8220;imagecreatefrom$tmp&#8221;;<br />
        $outfunc = &#8220;image$tmp&#8221;;</p>
<p>        $fimg = $infunc($f);</p>
<p>        if($fw/$tw &gt; $fh/$th){<br />
                $fw = $tw * ($fh/$th);<br />
        }else{<br />
                $fh = $th * ($fw/$tw);<br />
        }</p>
<p>        $timg = imagecreatetruecolor($tw, $th);<br />
        imagecopyresampled($timg, $fimg, 0,0, 0,0, $tw,$th, $fw,$fh);<br />
        if($outfunc($timg, $t)){<br />
                return true;<br />
        }else{<br />
                return false;<br />
        }<br />
}<br />
?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/171.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php学习点滴-Failed to initialize storage module解决方法</title>
		<link>http://www.tisswb.com/archives/119.html</link>
		<comments>http://www.tisswb.com/archives/119.html#comments</comments>
		<pubDate>Sat, 20 Sep 2008 13:48:53 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php学习点滴]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=119</guid>
		<description><![CDATA[今天更新了一下自己的cms，然后后台就提示登陆不了，报错如下：Failed to initialize storage module。
解决方法有两种如下：
1。在报错的文件里的session start();之前加入如下代码：ini_set(&#8216;session.save_handler&#8217;, &#8216;files&#8217;); 。这种方法适合租用空间的用户使用。
2。在php.ini文件里，显式指定session的save_path(比如 c:/temp)然后重启web服务。如果服务器的管理权限属于你，那还是这样改比较方便。
原因分析：php5一个安全模式的bug，默认session的save_path是系统的临时目录，这样会要校验权限。
]]></description>
			<content:encoded><![CDATA[<p>今天更新了一下自己的cms，然后后台就提示登陆不了，报错如下：Failed to initialize storage module。</p>
<p>解决方法有两种如下：</p>
<p>1。在报错的文件里的session start();之前加入如下代码：ini_set(&#8216;session.save_handler&#8217;, &#8216;files&#8217;); 。这种方法适合租用空间的用户使用。</p>
<p>2。在php.ini文件里，显式指定session的save_path(比如 c:/temp)然后重启web服务。如果服务器的管理权限属于你，那还是这样改比较方便。</p>
<p>原因分析：php5一个安全模式的bug，默认session的save_path是系统的临时目录，这样会要校验权限。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/119.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php学习点滴-php的函数前的@含义</title>
		<link>http://www.tisswb.com/archives/114.html</link>
		<comments>http://www.tisswb.com/archives/114.html#comments</comments>
		<pubDate>Fri, 05 Sep 2008 16:18:21 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php学习点滴]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=114</guid>
		<description><![CDATA[php的函数前的@含义：
例子:$connid=@mysql_connect(&#8220;$hostname&#8221;,&#8221;$dbusename&#8221;,&#8221;$dbpassword&#8221;) or die(&#8220;未连接数据库服务器&#8221;)
其中@表示加到任何函数前，不触发错误提示（如果发生错误的情况下）
]]></description>
			<content:encoded><![CDATA[<p><strong>php的函数前的@含义：</strong></p>
<p>例子:$connid=@mysql_connect(&#8220;$hostname&#8221;,&#8221;$dbusename&#8221;,&#8221;$dbpassword&#8221;) or die(&#8220;未连接数据库服务器&#8221;)</p>
<p>其中@表示加到任何函数前，不触发错误提示（如果发生错误的情况下）</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/114.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[原创] uchome1.2插件之强制上传照片</title>
		<link>http://www.tisswb.com/archives/106.html</link>
		<comments>http://www.tisswb.com/archives/106.html#comments</comments>
		<pubDate>Mon, 04 Aug 2008 17:03:16 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[uchome]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=106</guid>
		<description><![CDATA[1.添加函数在function_common.php中
//检测是否上传头像
function isavatar($uid){
 $avatar = &#8216;../uc/data/avatar/&#8217;.get_avatar($uid, $size);
 if(!file_exists($avatar)) {
  showmessage(&#8216;do_not_have_avatar&#8217;, &#8216;cp.php&#8217;, 5);
 } 
}
//获得头像路径
function get_avatar($uid, $size = &#8216;middle&#8217;) {
<span class="readmore"><a href="http://www.tisswb.com/archives/106.html" title="[原创] uchome1.2插件之强制上传照片" target="_blank">阅读全文——共680字</a></span>]]></description>
			<content:encoded><![CDATA[<p><strong>1.添加函数在function_common.php中</strong><br />
//检测是否上传头像<br />
function isavatar($uid){<br />
 $avatar = &#8216;../uc/data/avatar/&#8217;.get_avatar($uid, $size);<br />
 if(!file_exists($avatar)) {<br />
  showmessage(&#8216;do_not_have_avatar&#8217;, &#8216;cp.php&#8217;, 5);<br />
 } <br />
}</p>
<p>//获得头像路径<br />
function get_avatar($uid, $size = &#8216;middle&#8217;) {<br />
 $size = in_array($size, array(&#8216;big&#8217;, &#8216;middle&#8217;, &#8216;small&#8217;)) ? $size : &#8216;middle&#8217;;<br />
 $uid = abs(intval($uid));<br />
 $uid = sprintf(&#8220;%09d&#8221;, $uid);<br />
 $dir1 = substr($uid, 0, 3);<br />
 $dir2 = substr($uid, 3, 2);<br />
 $dir3 = substr($uid, 5, 2);<br />
 return $dir1.&#8217;/&#8217;.$dir2.&#8217;/&#8217;.$dir3.&#8217;/&#8217;.substr($uid, -2).&#8221;_avatar_$size.jpg&#8221;;<br />
}</p>
<p><strong>2.在需要的页面添加如下代码</strong><br />
//检测是否上传照片<br />
isavatar($_SGLOBAL['supe_uid']);</p>
<p><strong>3.修改language下的message文件</strong><br />
&#8216;do_not_have_avatar&#8217; =&gt; &#8216;尊敬的用户：&lt;br&gt;　　您尚未上传照片，不能与好友正常交流！请您使用近期照片作为头像！&lt;br&gt;　　５秒钟后，系统将会自动帮您跳转到头像编辑界面．&#8217;,</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/106.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>get_magic_quotes_gpc 与 addslashes 用法详解</title>
		<link>http://www.tisswb.com/archives/91.html</link>
		<comments>http://www.tisswb.com/archives/91.html#comments</comments>
		<pubDate>Thu, 24 Jul 2008 16:18:01 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=91</guid>
		<description><![CDATA[int get_magic_quotes_gpc ( void )
本函式取得 PHP 环境设定的变数 magic_quotes_gpc (GPC, Get/Post/Cookie) 值。传回 0 表示关闭本功能；传回 1 表示本功能开启。当 magic_quotes_gpc 开启时，所有的 &#8216; (单引号), &#8221; (双引号),  (反斜线) and 空字符会自动转为含有反斜线的溢出字符。
string addslashes ( string str )
返回字符串，该字符串为了数据库查询语句等的需要在某些字符前加上了反斜线。这些字符是单引号（&#8216;）、双引号（&#8220;）、反斜线（）与 NUL（NULL 字符）。
一个使用 addslashes() 的例子是当你要往数据库中输入数据时。例如，将名字 O&#8217;reilly 插入到数据库中，这就需要对其进行转义。大多数据库使用  作为转义符：O&#8217;reilly。这样可以将数据放入数据库中，而不会插入额外的 。当 PHP 指令 magic_quotes_sybase 被设置成 on 时，意味着插入 &#8216; 时将使用 &#8216; 进行转义。
<span class="readmore"><a href="http://www.tisswb.com/archives/91.html" title="get_magic_quotes_gpc 与 addslashes 用法详解" target="_blank">阅读全文——共694字</a></span>]]></description>
			<content:encoded><![CDATA[<p>int <strong class="methodname">get_magic_quotes_gpc</strong> ( void )</p>
<p>本函式取得 PHP 环境设定的变数 magic_quotes_gpc (GPC, Get/Post/Cookie) 值。传回 0 表示关闭本功能；传回 1 表示本功能开启。当 magic_quotes_gpc 开启时，所有的 &#8216; (单引号), &#8221; (双引号),  (反斜线) and 空字符会自动转为含有反斜线的溢出字符。</p>
<p>string <strong class="methodname">addslashes</strong> ( string str )</p>
<p>返回字符串，该字符串为了数据库查询语句等的需要在某些字符前加上了反斜线。这些字符是单引号（<var class="literal">&#8216;</var>）、双引号（<var class="literal">&#8220;</var>）、反斜线（<var class="literal"></var>）与 NUL（<tt class="constant"><strong><span style="font-family: 新宋体;">NULL</span></strong></tt> 字符）。</p>
<p>一个使用 <strong class="function">addslashes()</strong> 的例子是当你要往数据库中输入数据时。例如，将名字 <var class="literal">O&#8217;reilly</var> 插入到数据库中，这就需要对其进行转义。大多数据库使用 <var class="literal"></var> 作为转义符：<var class="literal">O&#8217;reilly</var>。这样可以将数据放入数据库中，而不会插入额外的 <var class="literal"></var>。当 PHP 指令 magic_quotes_sybase 被设置成 <var class="literal">on</var> 时，意味着插入 <var class="literal">&#8216;</var> 时将使用 <var class="literal">&#8216;</var> 进行转义。</p>
<p>默认情况下，PHP 指令 magic_quotes_gpc 为 <var class="literal">on</var>，它主要是对所有的 GET、POST 和 COOKIE 数据自动运行 <strong class="function">addslashes()</strong>。不要对已经被 magic_quotes_gpc 转义过的字符串使用 <strong class="function">addslashes()</strong>，因为这样会导致双层转义。遇到这种情况时可以使用函数 <strong class="function">get_magic_quotes_gpc()</strong> 进行检测。</p>
<p>所以我们自定义一个转义函数：</p>
<p>function my_addslashes($str){<br />
return get_magic_quotes_gpc() ? $str : addslashes($str);<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/91.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP5中的this,self和parent关键字详解</title>
		<link>http://www.tisswb.com/archives/89.html</link>
		<comments>http://www.tisswb.com/archives/89.html#comments</comments>
		<pubDate>Thu, 24 Jul 2008 15:55:29 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=89</guid>
		<description><![CDATA[PHP5是一具备了大部分面向对象语言的特性的语言,比PHP4有了很多的面向对象的特性,但是有部分概念也比较绕人,所以今天拿出来说说,说的不好,请高手见谅. (阅读本文，需要了解PHP5的面向对象的知识)
首先我们来明白上面三个关键字: this,self,parent,从字面上比较好理解,是指这,自己,父亲,呵呵,比较好玩了,我们先建立几个概念,这三个关键字分别是用在什么地方呢?我们初步解释一下,this是指向当前对象的指针(我们姑且用C里面的指针来看吧),self是指向当前类的指针,parent是指向父类的指针。我们这里频繁使用指针来描述，是因为没有更好的语言来表达，呵呵，语文没学好。 -_-#
这么说还不能很了解，那我们就根据实际的例子结合来讲讲。
(1) this
1 &#60;?php
2
3 class UserName
4 { 
5     //定义属性   
6     private $name;
<span class="readmore"><a href="http://www.tisswb.com/archives/89.html" title="PHP5中的this,self和parent关键字详解" target="_blank">阅读全文——共3032字</a></span>]]></description>
			<content:encoded><![CDATA[<p>PHP5是一具备了大部分面向对象语言的特性的语言,比PHP4有了很多的面向对象的特性,但是有部分概念也比较绕人,所以今天拿出来说说,说的不好,请高手见谅. (阅读本文，需要了解PHP5的面向对象的知识)</p>
<p>首先我们来明白上面三个关键字: this,self,parent,从字面上比较好理解,是指这,自己,父亲,呵呵,比较好玩了,我们先建立几个概念,这三个关键字分别是用在什么地方呢?我们初步解释一下,this是指向当前对象的指针(我们姑且用C里面的指针来看吧),self是指向当前类的指针,parent是指向父类的指针。我们这里频繁使用指针来描述，是因为没有更好的语言来表达，呵呵，语文没学好。 -_-#</p>
<p>这么说还不能很了解，那我们就根据实际的例子结合来讲讲。<br />
<strong><span style="color: #000080; background-color: #ffffff;">(1) this</span></strong></p>
<p>1 &lt;?php<br />
2<br />
3 class UserName<br />
4 { <br />
5     //定义属性   <br />
6     private $name;<br />
7 <br />
8     //定义构造函数<br />
9     function __construct( $name )<br />
10     {<br />
11          $this-&gt;name = $name; //这里已经使用了this指针<br />
12     }<br />
13 <br />
14     //析构函数<br />
15     function __destruct(){}<br />
16<br />
17     //打印用户名成员函数<br />
18     function printName()<br />
19     {<br />
20          print( $this-&gt;name ); //又使用了this指针<br />
21     }<br />
22 }<br />
23<br />
24 //实例化对象<br />
25 $nameObject = new UserName( &#8220;heiyeluren&#8221; );<br />
26<br />
27 //执行打印<br />
28 $nameObject-&gt;printName(); //输出: heiyeluren<br />
29<br />
30 //第二次实例化对象<br />
31 $nameObject2 = new UserName( &#8220;PHP5&#8243; );<br />
32<br />
33 //执行打印<br />
34 $nameObject2-&gt;printName(); //输出：PHP5<br />
35 ?&gt;</p>
<p>我们看，上面的类分别在11行和20行使用了this指针，那么当时this是指向谁呢？其实this是在实例化的时候来确定指向谁，比如第一次实例化对象的时候(25行)，那么当时this就是指向$nameObject对象，那么执行18行的打印的时候就把print( $this-&gt;&lt;name )变成了print( $nameObject-&gt;name )，那么当然就输出了&#8221;heiyeluren&#8221;。第二个实例的时候，print( $this-&gt;name )变成了print( $nameObject2-&gt;name )，于是就输出了&#8221;PHP5&#8243;。所以说，this就是指向当前对象实例的指针，不指向任何其他对象或类。</p>
<p> </p>
<p><strong><span style="color: #000080; background-color: #ffffff;">(2)self</span></strong></p>
<p>首先我们要明确一点，self是指向类本身，也就是self是不指向任何已经实例化的对象，一般self使用来指向类中的静态变量。</p>
<p>1 &lt;?php<br />
2<br />
3     class Counter<br />
4     {<br />
5         //定义属性，包括一个静态变量<br />
6         private static $firstCount = 0;<br />
7         private $lastCount;<br />
8<br />
9         //构造函数<br />
10         function __construct()<br />
11         {<br />
12              $this-&gt;lastCount = ++selft::$firstCount; //使用self来调用静态变量,使用self调用必须使用::(域运算符号)<br />
13         }<br />
14<br />
15         //打印最次数值<br />
16         function printLastCount()<br />
17         {<br />
18              print( $this-&gt;lastCount );<br />
19         } <br />
20     }<br />
21<br />
22 //实例化对象<br />
23 $countObject = new Counter();<br />
24<br />
25 $countObject-&gt;printLastCount(); //输出 1<br />
26<br />
27 ?&gt;</p>
<p>我们这里只要注意两个地方，第6行和第12行。我们在第二行定义了一个静态变量$firstCount，并且初始值为0，那么在12行的时候调用了这个值得，使用的是self来调用，并且中间使用&#8221;::&#8221;来连接，就是我们所谓的域运算符，那么这时候我们调用的就是类自己定义的静态变量$frestCount，我们的静态变量与下面对象的实例无关，它只是跟类有关，那么我调用类本身的的，那么我们就无法使用this来引用，可以使用self来引用，因为self是指向类本身，与任何对象实例无关。换句话说，假如我们的类里面静态的成员，我们也必须使用self来调用。<br />
<span style="color: #000080; background-color: #ffffff;"><strong>(3)parent</strong></span></p>
<p>我们知道parent是指向父类的指针，一般我们使用parent来调用父类的构造函数。</p>
<p>1 &lt;?php<br />
2<br />
3 //基类<br />
4 class Animal<br />
5 {<br />
6     //基类的属性<br />
7     public $name; //名字<br />
8<br />
9     //基类的构造函数<br />
10     public function __construct( $name )<br />
11     {<br />
12          $this-&gt;name = $name;<br />
13     }<br />
14 }<br />
15<br />
16 //派生类<br />
17 class Person extends Animal //Person类继承了Animal类<br />
18 {<br />
19     public $personSex; //性别<br />
20     public $personAge; //年龄<br />
21<br />
22     //继承类的构造函数<br />
23     function __construct( $personSex, $personAge )<br />
24     {<br />
25          parent::__construct( &#8220;heiyeluren&#8221; ); //使用parent调用了父类的构造函数<br />
26          $this-&gt;personSex = $personSex;<br />
27          $this-&gt;personAge = $personAge;<br />
28     }<br />
29<br />
30     function printPerson()<br />
31     {<br />
32          print( $this-&gt;name. &#8221; is &#8221; .$this-&gt;personSex. &#8220;,this year &#8221; .$this-&gt;personAge );<br />
33      }<br />
34 }<br />
35<br />
36 //实例化Person对象<br />
37 $personObject = new Person( &#8220;male&#8221;, &#8220;21&#8243;);<br />
38<br />
39 //执行打印<br />
40 $personObject-&gt;printPerson(); //输出：heiyeluren is male,this year 21<br />
41<br />
42 ?&gt;<br />
我们注意这么几个细节：成员属性都是public的，特别是父类的，是为了供继承类通过this来访问。我们注意关键的地方，第25行：parent::__construct( &#8220;heiyeluren&#8221; ),这时候我们就使用parent来调用父类的构造函数进行对父类的初始化，因为父类的成员都是public的，于是我们就能够在继承类中直接使用this来调用。<br />
总结：</p>
<p>this是指向对象实例的一个指针，self是对类本身的一个引用，parent是对父类的引用。</p>
<p>基本上我所了解就这么多，肯定有理解错误之处，请高手指出！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/89.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP中利用GD库输出图像和汉字实例</title>
		<link>http://www.tisswb.com/archives/88.html</link>
		<comments>http://www.tisswb.com/archives/88.html#comments</comments>
		<pubDate>Wed, 23 Jul 2008 10:58:47 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[GD编程]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=88</guid>
		<description><![CDATA[一、原理
PHP中的GD库支持中文，但是必须要以UTF-8格式的参数来进行传递。下面先说一下汉字的UTF-8编码的求得。
用WORD2000或WINDOW 2000下的记事本编辑所要显示的汉字。 
把所编辑的文字存成格式为UTF-8格式的文件。 
用一个16进制的编辑器(如用PCTOOLS的EDIT功能)打开这个文件，这时会看到打开的文件里面有一些16进制的字符。一个汉字占三个字节，所以应该选择编辑汉字个数乘以3个字节的内容，把此编码记录下来以备后用。如赛迪网的代码是：E8 B5 9B E8 BF AA E7 BD 91
二、实现
本例中实现：赛迪网 www.tisswb.cn的图像输出。文件名为:ttf.php。&#60;?php
//定义输出为图像类型
header(&#8220;content-type:image/gif&#8221;);
//新建图象
<span class="readmore"><a href="http://www.tisswb.com/archives/88.html" title="PHP中利用GD库输出图像和汉字实例" target="_blank">阅读全文——共1229字</a></span>]]></description>
			<content:encoded><![CDATA[<table class="wr" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="gray14">一、原理<br />
PHP中的GD库支持中文，但是必须要以UTF-8格式的参数来进行传递。下面先说一下汉字的UTF-8编码的求得。</p>
<p>用WORD2000或WINDOW 2000下的记事本编辑所要显示的汉字。 <br />
把所编辑的文字存成格式为UTF-8格式的文件。 <br />
用一个16进制的编辑器(如用PCTOOLS的EDIT功能)打开这个文件，这时会看到打开的文件里面有一些16进制的字符。一个汉字占三个字节，所以应该选择编辑汉字个数乘以3个字节的内容，把此编码记录下来以备后用。如赛迪网的代码是：E8 B5 9B E8 BF AA E7 BD 91</p>
<p>二、实现<br />
本例中实现：赛迪网 <a href="http://www.tisswb.cn" target="_blank"><span style="color: #261cdc;">www.tisswb.cn</span></a>的图像输出。文件名为:ttf.php。&lt;?php<br />
//定义输出为图像类型<br />
header(&#8220;content-type:image/gif&#8221;);<br />
//新建图象<br />
$pic=imagecreate(240,30);<br />
//定义黑白颜色<br />
$black=imagecolorallocate($pic,0,0,0);<br />
$white=imagecolorallocate($pic,255,255,255);<br />
//定义字体<br />
$font=&#8221;c://WIN2000//fonts//simhei.ttf&#8221;;<br />
//定义输出字体串<br />
$str = chr(0xE8).chr(0xB5).chr(0x9B).chr(0xE8).chr(0xBF).chr(0xAA).chr(0xE7).chr(0xBD).chr(0&#215;91).&#8221; <a href="http://www.ccidnet.com/" target="_blank"><span style="color: #261cdc;">www.tisswb.com</span></a>&#8220;;<br />
//写 TTF 文字到图中<br />
imagettftext($pic,20,0,10,20,$white,$font,$str);<br />
//建立 GIF 图型<br />
imagegif($pic);<br />
//结束图形，释放内存空间<br />
imagedestroy($pic);<br />
?&gt;  </p>
<p>输出结果如图：</p>
<p>说明：<br />
汉字的引用方式为chr(编码)。如chr(0xE8).chr(0xB5).chr(0x9B)显示汉字。 <br />
ImageTTFText(int im, int size, int angle, int x, int y, int col, string fontfile, string text)：本函数将 TTF (TrueType Fonts) 字型文字写入图片。参数 size 为字形的尺寸；angle 为字型的角度，顺时针计算，0 度为水平，也就是三点钟的方向 (由左到右)，90 度则为由下到上的文字；x,y 二参数为文字的坐标值 (原点为左上角)；参数 col 为字的颜色；fontfile 为字型文件名称；text 是字符串内容。 <br />
必须安装GD库才能利用php中的图像处理函数。 <br />
图像引用方式：在需要的地方直接插入：&lt;img src=&#8221;ttf.php&#8221; border=0&gt;即可。</p>
<p>三、结束语<br />
PHP的GD库提供了相当完善的功能，充分利用其功能就能制作出各式各样的图形图像来，这样使页面内容更加丰富。</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/88.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php+mysql数据库编程学习小细节</title>
		<link>http://www.tisswb.com/archives/87.html</link>
		<comments>http://www.tisswb.com/archives/87.html#comments</comments>
		<pubDate>Tue, 22 Jul 2008 16:55:58 +0000</pubDate>
		<dc:creator>笨二十一</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web技术]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.tisswb.cn/?p=87</guid>
		<description><![CDATA[好多年没写程序了,现在对于php+mysql数据库编程都已经生疏了,最近又重新拾了起来,当然一开始就出现遇见了这样那样的问题.
1.乱码问题
按照以前的习惯写了代码如下；
$link = mysql_connect(&#8216;localhost&#8217;,'hgqy&#8217;,'hgqy&#8217;);　//连接数据服务器
mysql_select_db(&#8216;hgqy&#8217; , $link);　　//选择数据库
$sql = &#8220;select * from `plug＿qiye` where cpname = &#8216;济南&#8217;&#8221;;
$query = mysql_query($sql) or die(&#8220;查询失败&#8221; . mysql_error());　//执行数据查询语句
$row = mysql_fetch_array($query);
<span class="readmore"><a href="http://www.tisswb.com/archives/87.html" title="php+mysql数据库编程学习小细节" target="_blank">阅读全文——共522字</a></span>]]></description>
			<content:encoded><![CDATA[<p>好多年没写程序了,现在对于php+mysql数据库编程都已经生疏了,最近又重新拾了起来,当然一开始就出现遇见了这样那样的问题.<br />
1.<strong>乱码问题</strong><br />
按照以前的习惯写了代码如下；</p>
<blockquote><p>$link = mysql_connect(&#8216;localhost&#8217;,'hgqy&#8217;,'hgqy&#8217;);　//连接数据服务器</p>
<p>mysql_select_db(&#8216;hgqy&#8217; , $link);　　//选择数据库</p>
<p>$sql = &#8220;select * from `plug＿qiye` where cpname = &#8216;济南&#8217;&#8221;;</p>
<p>$query = mysql_query($sql) or die(&#8220;查询失败&#8221; . mysql_error());　//执行数据查询语句</p>
<p>$row = mysql_fetch_array($query);</p>
<p>foreach ($row as $i){<br />
　　　echo $i ;<br />
}</p></blockquote>
<p>输出的时候问题来了，没有任何输出，测试了所有我知道的方法，也没找到原因，于是就开始把 cpname = &#8216;济南&#8217;换成了id = 。终于找到问题了，输出的文字部分变成了乱码，傻了眼。<br />
在查阅资料后发现，原来在选择数据库后，需要再做一步</p>
<blockquote><p>mysql_query(&#8220;set names utf8&#8243;) ;　　//设定编码，utf8和gbk可以自行调整。</p></blockquote>
<p>这回终于可以正确输出了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tisswb.com/archives/87.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

