<?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://yanglu.org/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://yanglu.org</link>
	<description>天高任鸟飞，海阔凭鱼跃！</description>
	<lastBuildDate>Wed, 23 Nov 2011 06:04:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>ssh使用命令nohup php-cgi后台运行PHP</title>
		<link>http://yanglu.org/ssh_nohup_php_cgi/</link>
		<comments>http://yanglu.org/ssh_nohup_php_cgi/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 09:44:48 +0000</pubDate>
		<dc:creator>yanglu</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://yanglu.org/?p=346</guid>
		<description><![CDATA[使用ssh远程登录服务器的时候，要进行后台任务操作（比如采集），可以用命令nohup php-cgi来运行php，这样就可以关掉ssh客户端后还会在服务器上运行，运行的输出结果记录在用户目录下的nohup.out文件。]]></description>
			<content:encoded><![CDATA[<p>使用ssh远程登录服务器的时候，要进行后台任务操作（比如采集），可以用命令nohup php-cgi来运行php，这样就可以关掉ssh客户端后还会在服务器上运行，运行的输出结果记录在用户目录下的nohup.out文件。</p>
]]></content:encoded>
			<wfw:commentRss>http://yanglu.org/ssh_nohup_php_cgi/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SMARTY模板中如何使用get,post,request,cookies,session,server变量</title>
		<link>http://yanglu.org/smarty_get_post_request_cookie_ssession_server/</link>
		<comments>http://yanglu.org/smarty_get_post_request_cookie_ssession_server/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 05:54:11 +0000</pubDate>
		<dc:creator>yanglu</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://yanglu.org/?p=325</guid>
		<description><![CDATA[{$smarty}保留变量不需要从PHP脚本中分配，是可以在模板中直接访问的数组类型变量，通常被用于访问一些特殊的模板变量。例如，直接在模板中访问页面请求变量、获取访问模板时的时间邮戳、直接访问PHP中的常量、从配置文件中读取变量等。该保留变量中的部分访问介绍如下。 1．在模板中访问页面请求变量 我们可以在PHP脚本中，通过超级全局数组$_GET、$_POST、$_REQUEST获取在客户端以不同方法提交给服务器的数据，也可以通过$_COOKIE或$_SESSION在多个脚本之间跟踪变量，或是通过$_ENV和$_SERVER获取系统环境变量。如果在模板中需要这些数组，可以调用Smarty对象中的assign()方法分配给模板。但在Smarty模板中，直接就可以通过{$smarty}保留变量访问这些页面请求变量。在模板中使用的示例如下所示： 1.  {$smarty.get.page}            {* PHP方式：$_GET["page"] *}   2.  {$smarty.post.page}           {* PHP方式：$_POST["page"] *}   3.  {$smarty.cookies.username}    {* PHP方式：$_COOKIE["username"] *}   4.  {$smarty.session.id}          {* PHP方式：$_SESSION["id"] *}   5.  {$smarty.server.SERVER_NAME}  {* PHP方式：$_SERVER["SERVER_NAME"] *}   6.  {$smarty.env.PATH}            {* PHP方式：$_ENV["PATH"]*}   7.  {$smarty.request.username}    {* PHP方式：$_REQUEST["username"] *}  2．在模板中访问PHP中的变量 在PHP脚本中有系统常量和自定义常量两种，同样这两种常量在Smarty模板中也可以被访问，而且不需要从PHP中分配，只要通过{$smarty}保留变量就可以直接输出常量的值。在模板中输出常量的示例如下所示： 1.  {$smarty.const._MY_CONST_VAL} {* 输出PHP脚本中自定义的常量 *}   2.  {$smarty.const.__FILE__}     {* 通过保留变量数组直接输出系统常量 *}]]></description>
			<content:encoded><![CDATA[<p>{$smarty}保留变量不需要从PHP脚本中分配，是可以在模板中直接访问的数组类型变量，通常被用于访问一些特殊的模板变量。例如，直接在模板中访问页面请求变量、获取访问模板时的时间邮戳、直接访问PHP中的常量、从配置文件中读取变量等。该保留变量中的部分访问介绍如下。</p>
<p><strong>1</strong><strong>．在模板中访问页面请求变量</strong></p>
<p>我们可以在PHP脚本中，通过超级全局数组$_GET、$_POST、$_REQUEST获取在客户端以不同方法提交给服务器的数据，也可以通过$_COOKIE或$_SESSION在多个脚本之间跟踪变量，或是通过$_ENV和$_SERVER获取系统环境变量。如果在模板中需要这些数组，可以调用Smarty对象中的assign()方法分配给模板。但在Smarty模板中，直接就可以通过{$smarty}保留变量访问这些页面请求变量。在模板中使用的示例如下所示：<span id="more-325"></span></p>
<pre>1.  {$smarty.get.page}             {* PHP方式：$_GET["page"] *}  </pre>
<pre>2.  {$smarty.post.page}            {* PHP方式：$_POST["page"] *}  </pre>
<pre>3.  {$smarty.cookies.username}     {* PHP方式：$_COOKIE["username"] *}  </pre>
<pre>4.  {$smarty.session.id}           {* PHP方式：$_SESSION["id"] *}  </pre>
<pre>5.  {$smarty.server.SERVER_NAME}   {* PHP方式：$_SERVER["SERVER_NAME"] *}  </pre>
<pre>6.  {$smarty.env.PATH}             {* PHP方式：$_ENV["PATH"]*}  </pre>
<pre>7.  {$smarty.request.username}     {* PHP方式：$_REQUEST["username"] *} </pre>
<p><strong>2</strong><strong>．在模板中访问PHP中的变量</strong></p>
<p>在PHP脚本中有系统常量和自定义常量两种，同样这两种常量在Smarty模板中也可以被访问，而且不需要从PHP中分配，只要通过{$smarty}保留变量就可以直接输出常量的值。在模板中输出常量的示例如下所示：</p>
<pre>1.  {$smarty.<strong>const</strong>._MY_CONST_VAL} {* 输出PHP脚本中自定义的常量 *}  </pre>
<pre>2.  {$smarty.<strong>const</strong>.<strong>__FILE__</strong>}     {* 通过保留变量数组直接输出系统常量 *}</pre>
]]></content:encoded>
			<wfw:commentRss>http://yanglu.org/smarty_get_post_request_cookie_ssession_server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>php正则匹配中文</title>
		<link>http://yanglu.org/php_preg_match_chinese/</link>
		<comments>http://yanglu.org/php_preg_match_chinese/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 00:44:39 +0000</pubDate>
		<dc:creator>yanglu</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[正则]]></category>

		<guid isPermaLink="false">http://yanglu.org/?p=300</guid>
		<description><![CDATA[php正则匹配中文的方法： $str = &#34;04aol汉字&#34;; $pattern = &#34;/^(\d{2})([A-Za-z]{3})([&#34;.chr&#40;0xa1&#41;.&#34;-&#34;.chr&#40;0xff&#41;.&#34;]+)$/&#34;; if&#40;preg_match&#40;$pattern, $str, $tmp&#41;&#41; &#123; 　　var_export&#40;$tmp&#41;; &#125; 显示结果： array &#40; 　　0 =&#62; '04aol汉字', 　　1 =&#62; '04', 　　2 =&#62; 'aol', 　　3 =&#62; '汉字', &#41;]]></description>
			<content:encoded><![CDATA[<p>php正则匹配中文的方法：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;04aol汉字&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pattern</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/^(\d{2})([A-Za-z]{3})([&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0xa1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;-&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0xff</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;]+)$/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pattern</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tmp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
　　<span style="color: #990000;">var_export</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>显示结果：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>
　　<span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'04aol汉字'</span><span style="color: #339933;">,</span>
　　<span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'04'</span><span style="color: #339933;">,</span>
　　<span style="color: #cc66cc;">2</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'aol'</span><span style="color: #339933;">,</span>
　　<span style="color: #cc66cc;">3</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'汉字'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://yanglu.org/php_preg_match_chinese/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ignore_user_abort实现计划任务</title>
		<link>http://yanglu.org/phpignore_user_abort/</link>
		<comments>http://yanglu.org/phpignore_user_abort/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 07:30:37 +0000</pubDate>
		<dc:creator>yanglu</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://yanglu.org/?p=295</guid>
		<description><![CDATA[ignore_user_abort，这个函数可以帮助我们实现像linux中的cron一样实现计划任务，用户关掉浏览器后还可以执行。 使用方法：先使用函数set_time_limit(0)设置程序的执行时间为无限制。 例： 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 &#60;?php // Ignore user aborts and allow &#8230; <a href="http://yanglu.org/phpignore_user_abort/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>ignore_user_abort，这个函数可以帮助我们实现像linux中的cron一样实现计划任务，用户关掉浏览器后还可以执行。<br />
使用方法：先使用函数set_time_limit(0)设置程序的执行时间为无限制。<br />
例：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Ignore user aborts and allow the script</span>
<span style="color: #666666; font-style: italic;">// to run forever</span>
<span style="color: #990000;">ignore_user_abort</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">set_time_limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Testing connection handling in PHP'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Run a pointless loop that sometime</span>
<span style="color: #666666; font-style: italic;">// hopefully will make us click away from</span>
<span style="color: #666666; font-style: italic;">// page or click the &quot;Stop&quot; button.</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Did the connection fail?</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">connection_status</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> CONNECTION_NORMAL<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Sleep for 10 seconds</span>
    <span style="color: #990000;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// If this is reached, then the 'break'</span>
<span style="color: #666666; font-style: italic;">// was triggered from inside the while loop</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// So here we can log, or perform any other tasks</span>
<span style="color: #666666; font-style: italic;">// we need without actually being dependent on the</span>
<span style="color: #666666; font-style: italic;">// browser.</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://yanglu.org/phpignore_user_abort/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>php配置变量写入配置文件的方法</title>
		<link>http://yanglu.org/php_discuz_file_get_put/</link>
		<comments>http://yanglu.org/php_discuz_file_get_put/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 07:51:47 +0000</pubDate>
		<dc:creator>yanglu</dc:creator>
				<category><![CDATA[Discuz!]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://yanglu.org/?p=277</guid>
		<description><![CDATA[有些常用的配置变量写入MYSQL比较麻烦，可以写入一个php配置文件，在需要的地方引入这个配置文件即可。写入方法如下(摘入)： $configfile = @file_get_contents&#40;'./config.inc.php'&#41;; $configfile = trim&#40;$configfile&#41;; $configfile = preg_replace&#40;&#34;/[$]dbhost\s*\=\s*[\&#34;'].*?[\&#34;'];/is&#34;, &#34;\$dbhost = '$dbhost';&#34;, $configfile&#41;; $configfile = preg_replace&#40;&#34;/[$]dbuser\s*\=\s*[\&#34;'].*?[\&#34;'];/is&#34;, &#34;\$dbuser = '$dbuser';&#34;, $configfile&#41;; $configfile = preg_replace&#40;&#34;/[$]dbpw\s*\=\s*[\&#34;'].*?[\&#34;'];/is&#34;, &#34;\$dbpw = '$dbpw';&#34;, $configfile&#41;; $configfile = preg_replace&#40;&#34;/[$]dbname\s*\=\s*[\&#34;'].*?[\&#34;'];/is&#34;, &#34;\$dbname = '$dbname';&#34;, $configfile&#41;; $configfile = preg_replace&#40;&#34;/[$]adminemail\s*\=\s*[\&#34;'].*?[\&#34;'];/is&#34;, &#34;\$adminemail = &#8230; <a href="http://yanglu.org/php_discuz_file_get_put/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>有些常用的配置变量写入MYSQL比较麻烦，可以写入一个php配置文件，在需要的地方引入这个配置文件即可。写入方法如下(摘入)：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$configfile</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./config.inc.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$configfile</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$configfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$configfile</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[$]dbhost\s*\=\s*[<span style="color: #000099; font-weight: bold;">\&quot;</span>'].*?[<span style="color: #000099; font-weight: bold;">\&quot;</span>'];/is&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\$</span>dbhost = '<span style="color: #006699; font-weight: bold;">$dbhost</span>';&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$configfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$configfile</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[$]dbuser\s*\=\s*[<span style="color: #000099; font-weight: bold;">\&quot;</span>'].*?[<span style="color: #000099; font-weight: bold;">\&quot;</span>'];/is&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\$</span>dbuser = '<span style="color: #006699; font-weight: bold;">$dbuser</span>';&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$configfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$configfile</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[$]dbpw\s*\=\s*[<span style="color: #000099; font-weight: bold;">\&quot;</span>'].*?[<span style="color: #000099; font-weight: bold;">\&quot;</span>'];/is&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\$</span>dbpw = '<span style="color: #006699; font-weight: bold;">$dbpw</span>';&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$configfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$configfile</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[$]dbname\s*\=\s*[<span style="color: #000099; font-weight: bold;">\&quot;</span>'].*?[<span style="color: #000099; font-weight: bold;">\&quot;</span>'];/is&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\$</span>dbname = '<span style="color: #006699; font-weight: bold;">$dbname</span>';&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$configfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$configfile</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[$]adminemail\s*\=\s*[<span style="color: #000099; font-weight: bold;">\&quot;</span>'].*?[<span style="color: #000099; font-weight: bold;">\&quot;</span>'];/is&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\$</span>adminemail = '<span style="color: #006699; font-weight: bold;">$adminemail</span>';&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$configfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$configfile</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[$]tablepre\s*\=\s*[<span style="color: #000099; font-weight: bold;">\&quot;</span>'].*?[<span style="color: #000099; font-weight: bold;">\&quot;</span>'];/is&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\$</span>tablepre = '<span style="color: #006699; font-weight: bold;">$tablepre</span>';&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$configfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$configfile</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[$]cookiepre\s*\=\s*[<span style="color: #000099; font-weight: bold;">\&quot;</span>'].*?[<span style="color: #000099; font-weight: bold;">\&quot;</span>'];/is&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\$</span>cookiepre = '&quot;</span><span style="color: #339933;">.</span>random<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;_';&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$configfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #339933;">@</span><span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./config.inc.php'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$configfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://yanglu.org/php_discuz_file_get_put/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP文件下载 浏览器显示文件名乱码问题</title>
		<link>http://yanglu.org/php_download_filename_charset/</link>
		<comments>http://yanglu.org/php_download_filename_charset/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 03:10:33 +0000</pubDate>
		<dc:creator>yanglu</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[网页制作]]></category>
		<category><![CDATA[字符编码]]></category>

		<guid isPermaLink="false">http://yanglu.org/?p=269</guid>
		<description><![CDATA[&#60;?php $filename = &#34;下载文件名&#34;; $filesize = filesize&#40;'文件地址'&#41;; //获得文件大小 header&#40;'Pragma: public'&#41;; header&#40;'Last-Modified: '.gmdate&#40;'D, d M Y H:i:s'&#41; . ' GMT'&#41;; header&#40;'Cache-Control: no-store, no-cache, must-revalidate'&#41;; header&#40;'Cache-Control: pre-check=0, post-check=0, max-age=0'&#41;; header&#40;'Content-Transfer-Encoding: binary'&#41;; header&#40;'Content-Encoding: none'&#41;; header&#40;'Content-type: application/force-download'&#41;; header&#40;'Content-Disposition: attachment; filename=&#34;'.$filename.'&#34;'&#41;; header&#40;'Content-length: '.$filesize&#41;; ?&#62; 这样在弹出文件下载框时，显示的文件名在不同的浏览器下面是不一样的。有的是乱码，有的是空白。 &#8230; <a href="http://yanglu.org/php_download_filename_charset/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;下载文件名&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$filesize</span> <span style="color: #339933;">=</span> <span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'文件地址'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//获得文件大小</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Pragma: public'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Last-Modified: '</span><span style="color: #339933;">.</span><span style="color: #990000;">gmdate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'D, d M Y H:i:s'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' GMT'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cache-Control: no-store, no-cache, must-revalidate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cache-Control: pre-check=0, post-check=0, max-age=0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Transfer-Encoding: binary'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Encoding: none'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: application/force-download'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Disposition: attachment; filename=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$filename</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-length: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$filesize</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>这样在弹出文件下载框时，显示的文件名在不同的浏览器下面是不一样的。有的是乱码，有的是空白。<br />
所以文件名统一使用utf-8编码，然后针对ie浏览器进行一次rawurlencode编码。<br />
把以下代码放在header之前</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span>’<span style="color: #339933;">/</span>MSIE<span style="color: #339933;">/</span>’<span style="color: #339933;">,</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rawurlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://yanglu.org/php_download_filename_charset/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

