﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>PHP博客-zwws's blog-随笔分类-PHP技巧</title><link>http://www.phpweblog.net/zwws/category/174.html</link><description>Blog For PHP Learning...</description><language>zh-cn</language><lastBuildDate>Wed, 28 Feb 2007 03:32:08 GMT</lastBuildDate><pubDate>Wed, 28 Feb 2007 03:32:08 GMT</pubDate><ttl>60</ttl><item><title>php实现首页自动选择语言转跳</title><link>http://www.phpweblog.net/zwws/archive/2007/02/19/922.html</link><dc:creator>zwws</dc:creator><author>zwws</author><pubDate>Sun, 18 Feb 2007 16:57:00 GMT</pubDate><guid>http://www.phpweblog.net/zwws/archive/2007/02/19/922.html</guid><wfw:comment>http://www.phpweblog.net/zwws/comments/922.html</wfw:comment><comments>http://www.phpweblog.net/zwws/archive/2007/02/19/922.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/zwws/comments/commentRss/922.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/zwws/services/trackbacks/922.html</trackback:ping><description><![CDATA[
		<p>很多网站在首页上做一些链接，让用户来选择将要访问的各自的语言页面，让中国人选择“中文”，韩国人选择“朝鲜语”，等等。那么能不能做程序来自动帮助选择呢？<br />答案是肯定的，大家都在用google，你用中文系统打开google的首页，打开的自然是中文首页，而不会是其他语言。因为google会自动判断用户系统使用的首选语言是什么。<br />怎样才能做到像google那样呢，其实很简单，<br />在浏览器发给web服务器的 HTTP Headers Information 中包含了这样一个信息 Accept-Language<br />这个信息就是，浏览器中 工具-&gt;Internet选项-&gt;常规 下的 语言， 它就是用来设置浏览器可接受的语言首选项的， 它可以是多种可接受语言的优先排序列。</p>
		<p>下面以PHP为例，<br />用户可接受的语言信息，放在$_SERVER['HTTP_ACCEPT_LANGUAGE']里，<br />变量信息是类似这样的 "zh-cn"， 如果是多语言列，是类似 "zh-cn,en;q=0.8,ko;q=0.5,zh-tw;q=0.3"<br />下面的问题可以迎刃而解了。</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">&lt;?</span>
				<span style="COLOR: #000000">php<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #008080">error_reporting</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #ff00ff">E_ALL</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">^</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff00ff">E_NOTICE</span>
				<span style="COLOR: #000000">);<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> 分析 HTTP_ACCEPT_LANGUAGE 的属性<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />// 这里只取第一语言设置 （其他可根据需要增强功能，这里只做简单的方法演示）</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #008080">preg_match</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">/^([a-z\-]+)/i</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #800080">$_SERVER</span>
				<span style="COLOR: #000000">[</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">HTTP_ACCEPT_LANGUAGE</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">]</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #800080">$matches</span>
				<span style="COLOR: #000000">);<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #800080">$lang</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #800080">$matches</span>
				<span style="COLOR: #000000">[</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">];<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">switch</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #800080">$lang</span>
				<span style="COLOR: #000000">) {<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">case</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">zh-cn</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">:</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />                </span>
				<span style="COLOR: #008080">header</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">Location: http://cn.example.com/</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">); <br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />                </span>
				<span style="COLOR: #0000ff">break</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">case</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">zh-tw</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">:</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />                </span>
				<span style="COLOR: #008080">header</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">Location: http://tw.example.com/</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">); <br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />                </span>
				<span style="COLOR: #0000ff">break</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">case</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">ko</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">:</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />                </span>
				<span style="COLOR: #008080">header</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">Location: http://ko.example.com/</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">); <br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />                </span>
				<span style="COLOR: #0000ff">break</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">default</span>
				<span style="COLOR: #000000">:</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />                </span>
				<span style="COLOR: #008080">header</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">Location: http://en.example.com/</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">); <br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />                </span>
				<span style="COLOR: #0000ff">break</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #000000">?&gt;</span>
				<span style="COLOR: #000000"> </span>
		</div>
<img src ="http://www.phpweblog.net/zwws/aggbug/922.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.phpweblog.net/zwws/" target="_blank">zwws</a> 2007-02-19 00:57 <a href="http://www.phpweblog.net/zwws/archive/2007/02/19/922.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP代码收集[标哥版]</title><link>http://www.phpweblog.net/zwws/archive/2007/02/18/920.html</link><dc:creator>zwws</dc:creator><author>zwws</author><pubDate>Sun, 18 Feb 2007 04:27:00 GMT</pubDate><guid>http://www.phpweblog.net/zwws/archive/2007/02/18/920.html</guid><wfw:comment>http://www.phpweblog.net/zwws/comments/920.html</wfw:comment><comments>http://www.phpweblog.net/zwws/archive/2007/02/18/920.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.phpweblog.net/zwws/comments/commentRss/920.html</wfw:commentRss><trackback:ping>http://www.phpweblog.net/zwws/services/trackbacks/920.html</trackback:ping><description><![CDATA[
		<p>收集自PHPChina 作者:标哥<br /><strong>1&gt;</strong><br /><u>问题描述：</u><br />输出结果排列问题想输出<br />结果5个一行,例如<br />000 001 002 003 004<br />005 006 007 008 009<br />代码尽量简洁<br /><u>解决方法：</u><br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #800080">$c</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">; </span>
				<span style="COLOR: #800080">$c</span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000">1000</span>
				<span style="COLOR: #000000">; </span>
				<span style="COLOR: #800080">$c</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />{<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #008080">printf</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">%03d%s</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #800080">$c</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #800080">$c</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #000000">%</span>
				<span style="COLOR: #000000">5</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">?</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">&lt;br&gt;</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">:</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">);<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />}</span>
		</div>
		<p>
				<br />
				<strong>2&gt;</strong>
				<br />
				<u>问题描述：</u>
				<br />$a,$b,$c,$d值=1时，则结果为true<br />$a = 1;  //TRUE<br />$b = 1;  //TRUE<br />$c = 2;  //FALSE<br />$d = 1;  //TRUE<br />那么想统计结果为true的语句个数应该写？</p>
		<p>
		</p>
		<p>
				<u>解决方法：</u>
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />
				<span>function find1() {<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #800080">$args</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span>func_get_args();<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #800080">$result</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008080">array_count_values</span>
				<span style="COLOR: #000000">(</span>
				<span>$args);<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #800080">$result</span>
				<span style="COLOR: #000000">[</span>
				<span>1];<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">echo</span>
				<span style="COLOR: #000000"> find1(</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">2</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">); </span>
		</div>
		<br />
		<strong>3&gt;<br /></strong>
		<u>问题描述：</u>
		<br />$a<br />$b<br />$c 
<p></p><p>1、$a不等于$b不等于$c应该怎么样写？<br />这个我用&amp;&amp;能写出来，不过感觉公式有点长，想问下有没有简便的语句？</p><p>2、$a等于$b但不等于$c<br />这个不大明白该怎么写</p><p><br /><u>解决方法：</u><br />1、$a不等于$b不等于$c应该怎么样写？<br />传统的方法： $a!=$b &amp;&amp; $b!=$c &amp;&amp; $b!=$c<br />写成函数：<br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" /><span>function checkDiff() {<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #800080">$args</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span>func_get_args();<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #008080">count</span><span style="COLOR: #000000">(</span><span style="COLOR: #008080">array_unique</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$args</span><span style="COLOR: #000000">)) </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #008080">count</span><span style="COLOR: #000000">(</span><span>$args);<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.phpweblog.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008080">var_export</span><span style="COLOR: #000000">( checkDiff(</span><span style="COLOR: #800080">$a</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$b</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$c</span><span style="COLOR: #000000">) );</span></div><br /><p>2、$a等于$b但不等于$c<br />$a==$b &amp;&amp; $b!=$c<br /></p><img src ="http://www.phpweblog.net/zwws/aggbug/920.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.phpweblog.net/zwws/" target="_blank">zwws</a> 2007-02-18 12:27 <a href="http://www.phpweblog.net/zwws/archive/2007/02/18/920.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>