<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[代码人生]]></title> 
<link>http://www.code-life.com/index.php</link> 
<description><![CDATA[阿东的代码人生]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[代码人生]]></copyright>
<item>
<link>http://www.code-life.com/read.php?108</link>
<title><![CDATA[[原]Windows下MEncoder下载和Linux下MEncoder的编译]]></title> 
<author>xudongding &lt;xudongding@yahoo.com.cn&gt;</author>
<category><![CDATA[网站开发]]></category>
<pubDate>Wed, 13 Jan 2010 06:27:02 +0000</pubDate> 
<guid>http://www.code-life.com/read.php?108</guid> 
<description>
<![CDATA[ 
	转载请注明出处 作者：阿东 来源：代码人生 www.code-life.com<br/><br/>2008年的一个项目由于要用到视频截图，研究了一番FFmpeg并写一篇博文<a href="http://www.code-life.com/read.php?61" target="_blank">[原]Windows下FFmpeg下载和Linux下FFmpeg的编译配置</a>分享了经验，也帮助了不少朋友解决了问题。最近一个项目要用到视频合并，而FFmpeg并不提供视频合并的功能，只能用MEncoder，于是乎又对MEncoder研究了一番，撰文以分享。<br/><br/>MEncoder是MPlayer自带的音视频编解码工具。MPlayer官方网站：<a href="http://www.mplayerhq.hu/" target="_blank">http://www.mplayerhq.hu/</a><br/><br/>和其他跨平台开源软件一样，Windows平台的一般使用已编译好的二进制程序包即可，Linux平台需要动手编译。<br/>Windows下MEncoder下载：<a href="http://sourceforge.net/projects/mplayer-win32/files/" target="_blank">http://sourceforge.net/projects/mplayer-win32/files/</a>（包含在MPlayer中）<br/><br/>OK，下面开始Linux下的MEncoder编译。实验机器的Linux发行版是CentOS 5.1。MEncoder编译要比FFmpeg编译简单的多，因为它提供了常用编解码器，而且在编译配置的时候会自动检测是否安装某个解码器而自动选择是否将其编译进去。<br/><br/>1.下载解压编解码器<br/>下载地址：<a href="http://www.mplayerhq.hu/MPlayer/releases/codecs/" target="_blank">http://www.mplayerhq.hu/MPlayer/releases/codecs/</a><br/>必要的解码器是essential-********.tar.bz2，而所有解码器为all-********.tar.bz2，为了支持更多的格式，当然选择下载所有了。<br/>下载后解压到某个目录，如/usr/local/lib/codecs，命令如下：<br/># tar jxvf all-********.tar.bz2<br/># mv all-******* /usr/local/lib/codecs<br/><br/>2.下载解压MPlayer源码<br/>可以使用SVN检出MPlayer的最新版本：<br/># svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer<br/>或者是下载每日更新包：<a href="http://www.mplayerhq.hu/MPlayer/releases/mplayer-checkout-snapshot.tar.bz2" target="_blank">http://www.mplayerhq.hu/MPlayer/releases/mplayer-checkout-snapshot.tar.bz2</a><br/>解压文件：<br/># tar jxvf mplayer-checkout-snapshot.tar.bz2<br/><br/>3.编译安装MPlayer<br/>进入源码目录，进行编译配置，重要的两个参数--prefix=/usr/local/mplayer安装目录和--codecsdir=/usr/local/lib/codecs解码器目录。如需要添加其它参数请使用./configure --help获取帮助。最后再编译安装。<br/># cd mplayer-checkout-****-**-**<br/># ./configure --prefix=/usr/local/mplayer --codecsdir=/usr/local/lib/codecs<br/># make<br/># make install<br/><br/>到此为止，已经成功了。比起FFmpeg编译要简单得多了。遇到问题的朋友请留言给我，但不要是诸如我怎么下载解压啊之类的初级问题。<br/>Tags - <a href="http://www.code-life.com/tag.php?tag=windows" rel="tag">windows</a> , <a href="http://www.code-life.com/tag.php?tag=linux" rel="tag">linux</a> , <a href="http://www.code-life.com/tag.php?tag=ffmpeg" rel="tag">ffmpeg</a> , <a href="http://www.code-life.com/tag.php?tag=mplayer" rel="tag">mplayer</a> , <a href="http://www.code-life.com/tag.php?tag=mencoder" rel="tag">mencoder</a>
]]>
</description>
</item><item>
<link>http://www.code-life.com/read.php?106</link>
<title><![CDATA[[整理/非原创]解决局域网连接到MySQL数据库速度慢的问题]]></title> 
<author>xudongding &lt;xudongding@yahoo.com.cn&gt;</author>
<category><![CDATA[网站开发]]></category>
<pubDate>Mon, 07 Dec 2009 05:52:58 +0000</pubDate> 
<guid>http://www.code-life.com/read.php?106</guid> 
<description>
<![CDATA[ 
	使用localhost连接本地MySQL数据库正常，但通过局域网另一台机器连接却异常缓慢。默认情况下，MySQL开启了域名反向解析，例如把192.168.0.12反向解析到devel，这样的域名反向解析需要耗费时间，一般情况下也没有必要。所以在MySQL数据库配置文件中(Windows为my.ini，Linux为my.cnf)，加入一行：<br/>skip-name-resolve<br/>重启MySQL即可。<br/>这样做的话授权表中访问的主机名只能使用IP了。如果需要使用主机名，请把相应的IP、主机名加入到hosts文件中(Windows是C:&#92;WINDOWS&#92;system32&#92;drivers&#92;etc&#92;hosts，Linux是/etc/hosts)。<br/>Tags - <a href="http://www.code-life.com/tag.php?tag=mysql" rel="tag">mysql</a>
]]>
</description>
</item><item>
<link>http://www.code-life.com/read.php?103</link>
<title><![CDATA[[原]MySQL忘记密码的解决办法]]></title> 
<author>xudongding &lt;xudongding@yahoo.com.cn&gt;</author>
<category><![CDATA[网站开发]]></category>
<pubDate>Wed, 22 Jul 2009 03:25:54 +0000</pubDate> 
<guid>http://www.code-life.com/read.php?103</guid> 
<description>
<![CDATA[ 
	MySQL密码存在数据库mysql中，所以就有了第一种方法替换法，用初始的mysql库(如果之前有备份的话，或者从其它地方拷贝过来)将现在的替换掉(MySQL的data目录下mysql目录)，即可恢复密码。这种方法相当于重置，有时候我们还设置了一些特定的权限，这时候就不适合用这种方法了。第二种方法，启动MySQL的时候忽略授权表，这样客户端就可以不用密码直接连接了，更新用户表即可，步骤如下。<br/>(1) 关闭MySQL<br/>Windows在命令提示符下输入net stop mysql，Linux输入命令service mysql stop。<br/>(2) 忽略授权表启动MySQL<br/>进入MySQL的bin目录，Windows输入mysqlnt --skip-grant-tables后不要关闭，Linux输入./safe_mysqld --skip-grant-tables &amp;。<br/>(3) 客户端连接<br/>进入MySQL的bin目录(Windows重新打开一个命令提示符窗口)，Windows输入mysql，Linux输入./mysql。依次输入SQL命令：<br/>&gt; use mysql;<br/>&gt; update user set password=password(&quot;new_password&quot;) where user=&quot;root&quot;;&nbsp;&nbsp;(注：new_password为新设置的密码)<br/>&gt; flush privileges;<br/>(4) 重新启动MySQL<br/>关闭MySQL，Windows将刚才的窗口关闭，Linux杀掉safe_mysqld的进程。正常启动MySQL即可。<br/>Tags - <a href="http://www.code-life.com/tag.php?tag=linux" rel="tag">linux</a> , <a href="http://www.code-life.com/tag.php?tag=mysql" rel="tag">mysql</a>
]]>
</description>
</item><item>
<link>http://www.code-life.com/read.php?100</link>
<title><![CDATA[Apache、MySQL及Subversion Windows服务安装]]></title> 
<author>xudongding &lt;xudongding@yahoo.com.cn&gt;</author>
<category><![CDATA[网站开发]]></category>
<pubDate>Thu, 14 May 2009 04:36:39 +0000</pubDate> 
<guid>http://www.code-life.com/read.php?100</guid> 
<description>
<![CDATA[ 
	下载免安装的Apache、MySQL和Subversion，我们需要手动将其添加为Windows服务以实现开机自启动。<br/><br/>1. Apache<br/>httpd -k install[ -n "Apache2.2"][ -f "conf/httpd.conf"]<br/>httpd.exe在bin目录下，Apache2.2为服务名(可省)，conf/httpd.conf为配置文件名(可省)。<br/><br/>2. MySQL<br/>sc create MySQL binpath= "&#92;"D:&#92;Server&#92;MySQL5.1&#92;bin&#92;mysqld&#92;" --defaults-file=&#92;"D:&#92;Server&#92;MySQL5.1&#92;my.ini&#92;" MySQL" start= auto<br/>sc为Windows添加/删除服务的工具，MySQL为服务名，D:&#92;Server&#92;MySQL5.1&#92;bin&#92;mysqld为mysqld的路径，D:&#92;Server&#92;MySQL5.1&#92;my.ini为配置文件，start= auto表示自动启动。<br/><br/>3. Subversion<br/>sc create svnserve binpath= "&#92;"D:&#92;Server&#92;SVN1.5&#92;bin&#92;svnserve.exe&#92;" --service --root &#92;"D:&#92;Server&#92;SVN1.5&#92;repos&#92;""[ displayname= "Subversion"] depend= tcpip start= auto<br/>svnserve为服务名，Subversion为显示名称(可省)，depend= tcpip表示此服务依赖于TCP/IP服务。<br/>Tags - <a href="http://www.code-life.com/tag.php?tag=windows" rel="tag">windows</a> , <a href="http://www.code-life.com/tag.php?tag=apache" rel="tag">apache</a> , <a href="http://www.code-life.com/tag.php?tag=mysql" rel="tag">mysql</a> , <a href="http://www.code-life.com/tag.php?tag=php" rel="tag">php</a> , <a href="http://www.code-life.com/tag.php?tag=subversion" rel="tag">subversion</a>
]]>
</description>
</item><item>
<link>http://www.code-life.com/read.php?91</link>
<title><![CDATA[[转]Using $_SERVER in PHP]]></title> 
<author>xudongding &lt;xudongding@yahoo.com.cn&gt;</author>
<category><![CDATA[网站开发]]></category>
<pubDate>Tue, 24 Feb 2009 09:07:31 +0000</pubDate> 
<guid>http://www.code-life.com/read.php?91</guid> 
<description>
<![CDATA[ 
	Using $_SERVER in PHP<br/>By Angela Bradley, About.com<br/><a href="http://php.about.com/od/learnphp/qt/_SERVER_PHP.htm" target="_blank">http://php.about.com/od/learnphp/qt/_SERVER_PHP.htm</a><br/><br/>$_SERVER[’PHP_SELF’], $_SERVER[&#039;REQUEST_URI&#039;], and $_SERVER[’SCRIPT_NAME’] all behave in similar ways, they return information about what file is being used. When exposed to some differnt scenarios, you can see in some cases they do behave differently. This can help you decide which is best for what you need in your script.<br/><br/>$_SERVER[’PHP_SELF’] <br/><br/>http://www.yoursite.com/example/ -- -- -- /example/index.php <br/><br/>http://www.yoursite.com/example/index.php -- -- -- /example/index.php <br/><br/>http://www.yoursite.com/example/index.php?a=test -- -- -- /example/index.php<br/><br/>http://www.yoursite.com/example/index.php/dir/test -- -- -- /dir/test <br/><br/>When we use $_SERVER[’PHP_SELF’] we have the file name /example/index.php returned to us both when we did and did not actully type it in the URL. When we appended variables to the end of it, they where truncated and again /example/index.php was returned. The only one that produced a different result was when we appended directories after the file name. In that case, it returned those directories. <br/><br/>$_SERVER[&#039;REQUEST_URI&#039;] <br/><br/>http://www.yoursite.com/example/ -- -- -- / <br/><br/>http://www.yoursite.com/example/index.php -- -- -- /example/index.php <br/><br/>http://www.yoursite.com/example/index.php?a=test -- -- -- /example/index.php?a=test<br/><br/>http://www.yoursite.com/example/index.php/dir/test -- -- -- /example/index.php/dir/test <br/><br/>In all of our examples, this returned exactly what we entered for the URL. It returned a plain /, the file name, the variables, and the appended directories, all just as they had been entered. <br/><br/>$_SERVER[’SCRIPT_NAME’] <br/><br/>http://www.yoursite.com/example/ -- -- -- /example/index.php <br/><br/>http://www.yoursite.com/example/index.php -- -- -- /example/index.php <br/><br/>http://www.yoursite.com/example/index.php?a=test -- -- -- /example/index.php<br/><br/>http://www.yoursite.com/example/index.php/dir/test -- -- -- /example/index.php <br/><br/>In all cases here we were returned only the file name /example/index.php regardless of if it was typed, not typed, or anything was appended to it.
]]>
</description>
</item><item>
<link>http://www.code-life.com/read.php?90</link>
<title><![CDATA[IE中window.location丢失的referer]]></title> 
<author>xudongding &lt;xudongding@yahoo.com.cn&gt;</author>
<category><![CDATA[网站开发]]></category>
<pubDate>Fri, 06 Feb 2009 06:05:35 +0000</pubDate> 
<guid>http://www.code-life.com/read.php?90</guid> 
<description>
<![CDATA[ 
	先看代码吧：<br/><div class="code">...<br/>&lt;script type=&quot;text/javascript&quot;&gt;<br/>function doConfirm(url, msg) &#123;<br/>&nbsp;&nbsp;var ret = confirm(msg);<br/>&nbsp;&nbsp;if(ret) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;window.location = url;<br/>&nbsp;&nbsp;&#125;<br/>&#125;<br/>&lt;/script&gt;<br/>&lt;a href=&quot;#&quot; onclick=&quot;doConfirm(&#039;process.php&#039;,&#039;确定要删除吗？&#039;)&quot;&gt;删除&lt;/a&gt;<br/>...</div>不直接链接到process.php为的是防止误操作导致数据删除，用JavaScript确认窗口来确认一次。<br/><br/>可就这样一个窗口确认在IE下却出了问题，我想在process.php处理过之后，再返回前一页，也就是上面代码的那一页，是动态页没有固定的URL，所以我要在process.php中获取前一页的referer，得到的却是空值。在Firefox、Opera和Chrome均能正确获取，看来这是IE的BUG。<br/><br/>Google了一下，第一条记录便是相关的，作者同样也遇到这样的问题，写得还挺详细：<a href="http://ianso.blogspot.com/2006/01/referer-header-not-set-on-http.html" target="_blank">"Referer" header not set on HTTP requests originating from assignment to "window.location" variable on IE6</a><br/><br/>修改一下即可：<br/><div class="code"> &lt;script type=&quot;text/javascript&quot;&gt;<br/>function doConfirm(url, msg) &#123;<br/>&nbsp;&nbsp;var ret = confirm(msg);<br/>&nbsp;&nbsp;if(ret) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;var a = document.createElement(&quot;a&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;if(!a.click) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.location = url;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;a.setAttribute(&quot;href&quot;, url);<br/>&nbsp;&nbsp;&nbsp;&nbsp;a.style.display = &quot;none&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;document.body.appendChild(a);<br/>&nbsp;&nbsp;&nbsp;&nbsp;a.click();<br/>&nbsp;&nbsp;&#125;<br/>&#125;<br/>&lt;/script&gt;</div>原理是在页面中创建一个a元素，设置href，然后点击。<br/>Tags - <a href="http://www.code-life.com/tag.php?tag=javascript" rel="tag">javascript</a> , <a href="http://www.code-life.com/tag.php?tag=ie" rel="tag">ie</a>
]]>
</description>
</item><item>
<link>http://www.code-life.com/read.php?88</link>
<title><![CDATA[iframe高度自适应（IE6+、FF、Opera、Chrome等测试通过）]]></title> 
<author>xudongding &lt;xudongding@yahoo.com.cn&gt;</author>
<category><![CDATA[网站开发]]></category>
<pubDate>Thu, 15 Jan 2009 04:25:45 +0000</pubDate> 
<guid>http://www.code-life.com/read.php?88</guid> 
<description>
<![CDATA[ 
	在主页面中对于嵌入的iframe页面高度未知，而且iframe页面的高度也不定，故不能在主页面中通过DOM来控制高度。在iframe页面中加入以下脚本便可实现：<br/><br/><div class="code">/*<br/>iframe 高度自适应脚本（IE6+、FF、Opera、Chrome等测试通过） 作者未知<br/>*/<br/>function iframeAutoFit() &#123;<br/>&nbsp;&nbsp;try &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;if(window != parent) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var a = parent.document.getElementsByTagName(&quot;IFRAME&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(var i = 0; i &lt; a.length; i++) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(a&#91;i&#93;.contentWindow == window) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var h1 = 0, h2 = 0, d = document, dd = d.documentElement;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&#91;i&#93;.parentNode.style.height = a&#91;i&#93;.offsetHeight +&quot;px&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&#91;i&#93;.style.height = &quot;10px&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(dd &amp;&amp; dd.scrollHeight) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h1=dd.scrollHeight;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(d.body) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h2 = d.body.scrollHeight;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var h = Math.max(h1, h2);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(document.all) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h += 4;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(window.opera) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h += 1;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&#91;i&#93;.style.height = a&#91;i&#93;.parentNode.style.height = h +&quot;px&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&#125; catch(ex) &#123;&#125;<br/>&#125;<br/><br/>if(window.attachEvent) &#123;<br/>&nbsp;&nbsp;window.attachEvent(&quot;onload&quot;, iframeAutoFit);<br/>&#125; else if(window.addEventListener) &#123;<br/>&nbsp;&nbsp;window.addEventListener(&quot;load&quot;, iframeAutoFit, false);<br/>&#125;</div><br/>Tags - <a href="http://www.code-life.com/tag.php?tag=iframe" rel="tag">iframe</a> , <a href="http://www.code-life.com/tag.php?tag=javascript" rel="tag">javascript</a> , <a href="http://www.code-life.com/tag.php?tag=ajax" rel="tag">ajax</a>
]]>
</description>
</item><item>
<link>http://www.code-life.com/read.php?87</link>
<title><![CDATA[PHP5手册、MySQL5手册英文版及中文版下载]]></title> 
<author>xudongding &lt;xudongding@yahoo.com.cn&gt;</author>
<category><![CDATA[网站开发]]></category>
<pubDate>Tue, 30 Dec 2008 04:03:10 +0000</pubDate> 
<guid>http://www.code-life.com/read.php?87</guid> 
<description>
<![CDATA[ 
	PHPer必备工具PHP5手册、MySQL5手册英文版及中文版下载。<br/><br/>1. PHP5手册中文版（带用户注释，中文无乱码）<br/><a href="attachment.php?fid=49">点击这里下载文件</a><br/>2. PHP5手册英文版<br/><a href="attachment.php?fid=50">点击这里下载文件</a><br/>3. MySQL5手册中文版<br/><a href="attachment.php?fid=51">点击这里下载文件</a><br/>4. MySQL5手册英文版<br/><a href="attachment.php?fid=52">点击这里下载文件</a><br/>Tags - <a href="http://www.code-life.com/tag.php?tag=php5%25E6%2589%258B%25E5%2586%258C" rel="tag">php5手册</a> , <a href="http://www.code-life.com/tag.php?tag=mysql5%25E6%2589%258B%25E5%2586%258C" rel="tag">mysql5手册</a>
]]>
</description>
</item><item>
<link>http://www.code-life.com/read.php?86</link>
<title><![CDATA[[原]使用PHP cURL扩展模拟浏览器抓取网页]]></title> 
<author>xudongding &lt;xudongding@yahoo.com.cn&gt;</author>
<category><![CDATA[网站开发]]></category>
<pubDate>Mon, 29 Dec 2008 04:28:55 +0000</pubDate> 
<guid>http://www.code-life.com/read.php?86</guid> 
<description>
<![CDATA[ 
	转载请注明出处 作者：阿东 来源：<a href="http://www.code-life.com/" target="_blank">http://www.code-life.com/</a><br/><br/>抓取网页内容，PHP内置了几个函数都可以实现，如file()、file_get_contents()等都支持URL参数。但要实现更复杂的操作，这些函数就无能为力了。<br/><br/>cURL是一个利用URL语法在命令行下工作的文件传输工具，cURL提供了一个PHP扩展，使用该扩展，可以完完全全地模拟浏览器操作，就像使用浏览器浏览一个网页一样，可以设置header内容、设置COOKIE数据、POST数据、上传文件、设置代理等。其实我们这里讨论的抓取网页内容，只是它的一个常用的应用罢了。<br/>cURL官方网站：<a href="http://curl.haxx.se/" target="_blank">http://curl.haxx.se/</a><br/>PHP cURL扩展：<a href="http://curl.haxx.se/libcurl/php/" target="_blank">http://curl.haxx.se/libcurl/php/</a><br/><br/>Windows下添加该扩展很简单，只要载入php_curl.dll即可。去掉php.ini文件extension=php_curl.dll前面的分号，将php_curl.dll拷入PHP扩展目录或C:&#92;Windows&#92;system32目录下重启Web服务器即可。php_curl.dll在PHP的ZIP包中提供。<br/><br/>Linux下需要先安装cURL，一个方法是将其编译进PHP，编译配置时候加上--with-curl[=DIR]，另一个方法是编译成PHP模块载入，编译cURL模块方法和编译其它PHP模块方法雷同，以下是基本的命令：<br/>cd /path/to/php/source 进入PHP源码目录<br/>cd ext/curl 进入cURL模块源码目录<br/>/usr/local/php/bin/phpize 生成编译配置文件<br/>./configure --with-php-config=/usr/local/php/bin/php-config<br/>make<br/>make install<br/>编译完成生成curl.so，修改php.ini，将该模块载入：<br/>extension=&quot;/path/to/extension/curl.so&quot;<br/><br/>测试cURL扩展是否载入，新建PHP文件：<br/>&lt;?php<br/>if(extension_loaded(&#039;curl&#039;)) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;echo &#039;cURL模块已载入！&#039;;<br/>&#125; else &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;echo &#039;cURL模块未载入！&#039;;<br/>&#125;<br/>?&gt;<br/><br/>抓取网页的例子：<br/>&lt;?php<br/>$url = &#039;http://www.baidu.com&#039;;&nbsp;&nbsp;// 抓取网页URL<br/>$ch = curl_init($url);&nbsp;&nbsp;// 初始化，返回一个handler<br/>curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);&nbsp;&nbsp;// 设置选项，有返回值<br/>curl_setopt($ch, CURLOPT_REFERER, &#039;http://www.google.cn/&#039;);&nbsp;&nbsp;// 设置选项，来源页，这意味着可以伪造referer达到不可告人的目的<br/>curl_setopt($ch, CURLOPT_USERAGENT, &#039;Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)&#039;);&nbsp;&nbsp;// 设置选项，浏览器信息<br/>$raw = curl_exec($ch);&nbsp;&nbsp;// 执行<br/>curl_close($ch);&nbsp;&nbsp;// 关闭handler<br/>echo $raw;&nbsp;&nbsp;// 输出结果<br/>?&gt;<br/><br/>curl_setopt()可设置很多选项，更多选项请参考PHP手册。<br/>更多函数及其用法请参考PHP手册(再次废话一句，以强调PHP手册真乃圣经也)。<br/>Tags - <a href="http://www.code-life.com/tag.php?tag=php" rel="tag">php</a> , <a href="http://www.code-life.com/tag.php?tag=curl" rel="tag">curl</a>
]]>
</description>
</item><item>
<link>http://www.code-life.com/read.php?4</link>
<title><![CDATA[PHPChina的PHP进阶学习连载]]></title> 
<author>xudongding &lt;xudongding@yahoo.com.cn&gt;</author>
<category><![CDATA[网站开发]]></category>
<pubDate>Mon, 22 Sep 2008 02:01:57 +0000</pubDate> 
<guid>http://www.code-life.com/read.php?4</guid> 
<description>
<![CDATA[ 
	<a href="http://www.phpchina.com/study/01/phpstudy.html" target="_blank">第1期：新手搭建环境篇</a><br/><a href="http://www.phpchina.com/study/02/phpstudy.html" target="_blank">第2期：网站基础建设篇HTML</a> <br/><a href="http://www.phpchina.com/study/03/phpstudy.html" target="_blank">第3期：CSS基础技术讲解篇</a> <br/><a href="http://www.phpchina.com/study/04/phpstudy.html" target="_blank">第4期：JavaSpcrip技术讲解</a> <br/><a href="http://www.phpchina.com/study/05/phpstudy.html" target="_blank">第5期：PHP开发环境ZEND专题</a> <br/><a href="http://www.phpchina.com/study/06/phpstudy.html" target="_blank">第6期：PHP新手入门专题 </a> <br/><a href="http://www.phpchina.com/study/07/phpstudy.html" target="_blank">第7期：PHP和MYSQL基础教程</a> <br/><a href="http://www.phpchina.com/study/08/phpstudy.html" target="_blank">第8期：MYSQL技巧与应用篇</a> <br/><a href="http://www.phpchina.com/study/08/phpstudy.html" target="_blank">第9期：Apache基础篇</a> <br/><a href="http://www.phpchina.com/study/10/phpstudy.html" target="_blank">第10期：PHP留言本实例讲解</a> <br/><a href="http://www.phpchina.com/study/11/phpstudy.html" target="_blank">第11期：PHP5 Web开发详解基础篇</a> <br/><a href="http://www.phpchina.com/study/12/phpstudy.html" target="_blank">第12期：PHP5 Web开发详解应用篇</a> <br/><a href="http://www.phpchina.com/study/13/phpstudy.html" target="_blank">第13期：PHP+Ajax Web开发基础篇</a> <br/><a href="http://www.phpchina.com/study/14/phpstudy.html" target="_blank">第14期：PHP+Ajax Web开发应用篇</a> <br/><a href="http://www.phpchina.com/study/15/phpstudy.html" target="_blank">第15期：正则表达式的技术应用</a><br/><a href="http://www.phpchina.com/study/16/phpstudy.html" target="_blank">第16期：PHP+XML基础篇</a><br/><a href="http://www.phpchina.com/study/17/phpstudy.html" target="_blank">第17期：PHP+XML的技术应用</a><br/><a href="http://www.phpchina.com/study/18/phpstudy.html" target="_blank">第18期：PHP邮件技术专题</a><br/><a href="http://www.phpchina.com/study/19/phpstudy.html" target="_blank">第19期：PEAR基础篇</a><br/><a href="http://www.phpchina.com/study/20/phpstudy.html" target="_blank">第20期：PEAR应用篇</a><br/><a href="http://www.phpchina.com/study/21/phpstudy.html" target="_blank">第21期：PHP专题</a><br/><a href="http://www.phpchina.com/study/22/phpstudy.html" target="_blank">第22期：聊天室专题</a><br/><a href="http://www.phpchina.com/study/23/phpstudy.html" target="_blank">第23期：PHP变量处理专题</a><br/><a href="http://www.phpchina.com/study/24/phpstudy.html" target="_blank">第24期：字符串处理专题</a><br/><a href="http://www.phpchina.com/study/25/phpstudy.html" target="_blank">第25期：函数使用专题</a><br/><a href="http://www.phpchina.com/study/26/phpstudy.html" target="_blank">第26期：文件与目录处理</a><br/><a href="http://www.phpchina.com/study/27/phpstudy.html" target="_blank">第27期：动态图象处理</a><br/><a href="http://www.phpchina.com/study/28/phpstudy.html" target="_blank">第28期：互联网应用中最重要IDE工具</a><br/>Tags - <a href="http://www.code-life.com/tag.php?tag=php" rel="tag">php</a> , <a href="http://www.code-life.com/tag.php?tag=phpchina" rel="tag">phpchina</a>
]]>
</description>
</item>
</channel>
</rss>