<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title></title>
		<link>http://www.jackfeng.com/category//</link>
		<description></description>
		<copyright>Copyright (C) 2004 Security Angel Team [S4T] All Rights Reserved.</copyright>
		<generator>SaBlog-X Version Plus 2.0 Build 20081001</generator>
		<lastBuildDate>Thu, 11 Mar 2010 01:30:53 +0000</lastBuildDate>
		<ttl>30</ttl>
		<item>
			<guid>http://www.jackfeng.com/archives/1365/</guid>
			<title>PHP 获取根域名</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p>&nbsp;function getUrlRoot($url){</p>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;#添加头部和尾巴</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;$url = $url . &quot;/&quot;;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;#判断域名</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;preg_match(&quot;/((\w*):\/\/)?\w*\.?([\w|-]*\.(com.cn|net.cn|gov.cn|org.cn|com|net|cn|org|asia|tel|mobi|me|tv|biz|cc|name|info))</div>
<div>\//&quot;, $url, $ohurl);</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;#判断IP</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if($ohurl[3] == ''){</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;preg_match(&quot;/((\d+\.){3}\d+)\//&quot;, $url, $ohip);</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return $ohip[1];</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return $ohurl[3];</div>
<div>}</div>]]></description>
			<link>http://www.jackfeng.com/archives/1365/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-11-13 13:58</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1364/</guid>
			<title>PHP socket 网络编程实例[转]</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p><span class="Apple-style-span" style="font-family: Arial; font-size: 12px; line-height: 18px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; color: rgb(0, 0, 0); ">SERVER端</span><br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(76, 131, 23); ">&lt;?php</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">//确保在连接客户端时不会超时</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 170, 170); ">set_time_limit</span>(<span style="line-height: normal; color: rgb(0, 153, 153); ">0</span>);<br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">//设置IP和端口号</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 0, 0); ">$address</span><span style="line-height: normal; color: rgb(0, 0, 0); ">=</span><span style="line-height: normal; color: rgb(170, 85, 0); ">'127.0.0.1'</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 0, 0); ">$port</span><span style="line-height: normal; color: rgb(0, 0, 0); ">=</span><span style="line-height: normal; color: rgb(0, 153, 153); ">2009</span>;&nbsp;&nbsp;&nbsp;&nbsp;<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">//调试的时候，可以多换端口来测试程序！</span><br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">//创建一个SOCKET</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">if</span>((<span style="line-height: normal; color: rgb(170, 0, 0); ">$sock</span><span style="line-height: normal; color: rgb(0, 0, 0); ">=</span><span style="line-height: normal; color: rgb(0, 170, 170); ">socket_create</span>(<span style="line-height: normal; color: rgb(0, 0, 0); ">AF_INET</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span><span style="line-height: normal; color: rgb(0, 0, 0); ">SOCK_STREAM</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span><span style="line-height: normal; color: rgb(0, 0, 0); ">SOL_TCP</span>))<span style="line-height: normal; color: rgb(0, 0, 0); ">&lt;</span><span style="line-height: normal; color: rgb(0, 153, 153); ">0</span>)<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">{</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;socket_create() 失败的原因是:&quot;</span><span style="line-height: normal; color: rgb(0, 0, 0); ">.</span><span style="line-height: normal; color: rgb(0, 170, 170); ">socket_strerror</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$sock</span>)<span style="line-height: normal; color: rgb(0, 0, 0); ">.</span><span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;&lt;br&gt;&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">}</span><br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">//绑定到socket端口</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">if</span>((<span style="line-height: normal; color: rgb(170, 0, 0); ">$ret</span><span style="line-height: normal; color: rgb(0, 0, 0); ">=</span><span style="line-height: normal; color: rgb(0, 170, 170); ">socket_bind</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$sock</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span><span style="line-height: normal; color: rgb(170, 0, 0); ">$address</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span><span style="line-height: normal; color: rgb(170, 0, 0); ">$port</span>))<span style="line-height: normal; color: rgb(0, 0, 0); ">&lt;</span><span style="line-height: normal; color: rgb(0, 153, 153); ">0</span>)<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">{</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;socket_bind() 失败的原因是:&quot;</span><span style="line-height: normal; color: rgb(0, 0, 0); ">.</span><span style="line-height: normal; color: rgb(0, 170, 170); ">socket_strerror</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$ret</span>)<span style="line-height: normal; color: rgb(0, 0, 0); ">.</span><span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;&lt;br&gt;&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">}</span><br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">//开始监听</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">if</span>((<span style="line-height: normal; color: rgb(170, 0, 0); ">$ret</span><span style="line-height: normal; color: rgb(0, 0, 0); ">=</span><span style="line-height: normal; color: rgb(0, 170, 170); ">socket_listen</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$sock</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span><span style="line-height: normal; color: rgb(0, 153, 153); ">4</span>))<span style="line-height: normal; color: rgb(0, 0, 0); ">&lt;</span><span style="line-height: normal; color: rgb(0, 153, 153); ">0</span>)<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">{</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;socket_listen() 失败的原因是:&quot;</span><span style="line-height: normal; color: rgb(0, 0, 0); ">.</span><span style="line-height: normal; color: rgb(0, 170, 170); ">socket_strerror</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$ret</span>)<span style="line-height: normal; color: rgb(0, 0, 0); ">.</span><span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;&lt;br&gt;&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">}</span><br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">do</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">{</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">if</span>&nbsp;((<span style="line-height: normal; color: rgb(170, 0, 0); ">$msgsock</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">=</span>&nbsp;<span style="line-height: normal; color: rgb(0, 170, 170); ">socket_accept</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$sock</span>))&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">&lt;</span>&nbsp;<span style="line-height: normal; color: rgb(0, 153, 153); ">0</span>)<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">{</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;socket_accept() failed: reason: &quot;</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">.</span>&nbsp;<span style="line-height: normal; color: rgb(0, 170, 170); ">socket_strerror</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$msgsock</span>)&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">.</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;</span><span style="line-height: normal; color: rgb(170, 85, 0); ">\n</span><span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">break</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">}</span><br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">//发到客户端</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 0, 0); ">$msg</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">=</span><span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;&lt;font color=red&gt;欢迎进入服务器！&lt;/font&gt;&lt;br&gt;&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 170, 170); ">socket_write</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$msgsock</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span>&nbsp;<span style="line-height: normal; color: rgb(170, 0, 0); ">$msg</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span>&nbsp;<span style="line-height: normal; color: rgb(0, 170, 170); ">strlen</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$msg</span>));<br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;读取客户端发来的信息&lt;br&gt;&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 0, 0); ">$buf</span><span style="line-height: normal; color: rgb(0, 0, 0); ">&nbsp;=</span><span style="line-height: normal; color: rgb(0, 170, 170); ">&nbsp;socket_read</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$msgsock</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span><span style="line-height: normal; color: rgb(0, 153, 153); ">8192</span>);<br style="line-height: normal; " />
<br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 0, 0); ">$talkback</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">=</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;收到的信息:</span><span style="line-height: normal; color: rgb(170, 85, 0); ">$buf</span><span style="line-height: normal; color: rgb(170, 85, 0); ">&lt;br&gt;&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 0, 0); ">$talkback</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">/* if(socket_write($msgsock, $talkback, strlen($talkback))&lt;0)</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">&nbsp;&nbsp;&nbsp;&nbsp; {</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;socket_write() failed: reason: &quot; . socket_strerror($msgsock) . &quot;\n&quot;;</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">&nbsp;&nbsp;&nbsp;&nbsp; }</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">&nbsp;&nbsp;&nbsp;&nbsp; else</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">&nbsp;&nbsp;&nbsp;&nbsp; {</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;发送成功&quot;;</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">&nbsp;&nbsp;&nbsp;&nbsp; }*/</span><br style="line-height: normal; " />
<br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 170, 170); font-style: italic; ">//echo $buf;</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 170, 170); ">socket_close</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$msgsock</span>);<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">}</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 170); ">while</span>&nbsp;(<span style="line-height: normal; color: rgb(0, 0, 170); ">true</span>);<br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 170, 170); ">socket_close</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$sock</span>);<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(76, 131, 23); ">?&gt;</span><br style="line-height: normal; " />
<br style="line-height: normal; " />
<br style="line-height: normal; " />
<br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">CLIENT端</span><br style="line-height: normal; " />
<br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(76, 131, 23); ">&lt;?php</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 170, 170); ">error_reporting</span>(<span style="line-height: normal; color: rgb(0, 0, 170); ">E_ALL</span>);<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 170, 170); ">set_time_limit</span>(<span style="line-height: normal; color: rgb(0, 153, 153); ">0</span>);<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;&lt;h2&gt;TCP/IP Connection&lt;/h2&gt;</span><span style="line-height: normal; color: rgb(170, 85, 0); ">\n</span><span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;</span>;<br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 0, 0); ">$service_port</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">=</span>&nbsp;<span style="line-height: normal; color: rgb(0, 153, 153); ">2009</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 0, 0); ">$address</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">=</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;127.0.0.1&quot;</span>;<br style="line-height: normal; " />
<br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 0, 0); ">$socket</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">=</span>&nbsp;<span style="line-height: normal; color: rgb(0, 170, 170); ">socket_create</span>(<span style="line-height: normal; color: rgb(0, 0, 0); ">AF_INET</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">SOCK_STREAM</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">SOL_TCP</span>);<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">if</span>&nbsp;(<span style="line-height: normal; color: rgb(170, 0, 0); ">$socket</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">&lt;</span>&nbsp;<span style="line-height: normal; color: rgb(0, 153, 153); ">0</span>)<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">{</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;socket_create() failed: reason: &quot;</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">.</span>&nbsp;<span style="line-height: normal; color: rgb(0, 170, 170); ">socket_strerror</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$socket</span>)&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">.</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;</span><span style="line-height: normal; color: rgb(170, 85, 0); ">\n</span><span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">}</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">else</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">{</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;OK.</span><span style="line-height: normal; color: rgb(170, 85, 0); ">\n</span><span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">}</span><br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;试图连接 '</span><span style="line-height: normal; color: rgb(170, 85, 0); ">$address</span><span style="line-height: normal; color: rgb(170, 85, 0); ">' 端口 '</span><span style="line-height: normal; color: rgb(170, 85, 0); ">$service_port</span><span style="line-height: normal; color: rgb(170, 85, 0); ">'...&lt;br&gt;&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 0, 0); ">$result</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">=</span>&nbsp;<span style="line-height: normal; color: rgb(0, 170, 170); ">socket_connect</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$socket</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span>&nbsp;<span style="line-height: normal; color: rgb(170, 0, 0); ">$address</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span>&nbsp;<span style="line-height: normal; color: rgb(170, 0, 0); ">$service_port</span>);<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">if</span>&nbsp;(<span style="line-height: normal; color: rgb(170, 0, 0); ">$result</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">&lt;</span>&nbsp;<span style="line-height: normal; color: rgb(0, 153, 153); ">0</span>)<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">{</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;socket_connect() failed.</span><span style="line-height: normal; color: rgb(170, 85, 0); ">\n</span><span style="line-height: normal; color: rgb(170, 85, 0); ">Reason: (</span><span style="line-height: normal; color: rgb(170, 85, 0); ">$result</span><span style="line-height: normal; color: rgb(170, 85, 0); ">) &quot;</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">.</span>&nbsp;<span style="line-height: normal; color: rgb(0, 170, 170); ">socket_strerror</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$result</span>)&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">.</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;</span><span style="line-height: normal; color: rgb(170, 85, 0); ">\n</span><span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">}</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">else</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">{</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;连接OK&lt;br&gt;&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">}</span><br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 0, 0); ">$in</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">=</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;Hello</span><span style="line-height: normal; color: rgb(170, 85, 0); ">\r\n</span><span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 0, 0); ">$in</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">.=</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;我是Chester</span><span style="line-height: normal; color: rgb(170, 85, 0); ">\r\n</span><span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 0, 0); ">$out</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">=</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">''</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(170, 0, 0); ">$out1</span><span style="line-height: normal; color: rgb(0, 0, 0); ">=</span><span style="line-height: normal; color: rgb(170, 85, 0); ">''</span>;<br style="line-height: normal; " />
<br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">if</span>(<span style="line-height: normal; color: rgb(0, 0, 0); ">!</span><span style="line-height: normal; color: rgb(0, 170, 170); ">socket_write</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$socket</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span>&nbsp;<span style="line-height: normal; color: rgb(170, 0, 0); ">$in</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span>&nbsp;<span style="line-height: normal; color: rgb(0, 170, 170); ">strlen</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$in</span>)))<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">{</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;socket_write() failed: reason: &quot;</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">.</span>&nbsp;<span style="line-height: normal; color: rgb(0, 170, 170); ">socket_strerror</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$socket</span>)&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">.</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;</span><span style="line-height: normal; color: rgb(170, 85, 0); ">\n</span><span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">}</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">else</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">{</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;发送到服务器信息成功！&lt;br&gt;&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;发送的内容为:&lt;font color='red'&gt;</span><span style="line-height: normal; color: rgb(170, 85, 0); ">$in</span><span style="line-height: normal; color: rgb(170, 85, 0); ">&lt;/font&gt; &lt;br&gt;&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">}</span><br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">while</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$out</span>&nbsp;<span style="line-height: normal; color: rgb(0, 0, 0); ">=</span>&nbsp;<span style="line-height: normal; color: rgb(0, 170, 170); ">socket_read</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$socket</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span>&nbsp;<span style="line-height: normal; color: rgb(0, 153, 153); ">8192</span>))<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">{</span><br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;接收服务器回传信息成功！&lt;br&gt;&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;接受的内容为:&quot;</span><span style="line-height: normal; color: rgb(0, 0, 0); ">,</span><span style="line-height: normal; color: rgb(170, 0, 0); ">$out</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 0); ">}</span><br style="line-height: normal; " />
<br style="line-height: normal; " />
<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;关闭SOCKET...&lt;br&gt;&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 170, 170); ">socket_close</span>(<span style="line-height: normal; color: rgb(170, 0, 0); ">$socket</span>);<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(0, 0, 170); ">echo</span>&nbsp;<span style="line-height: normal; color: rgb(170, 85, 0); ">&quot;关闭OK&lt;br&gt;&quot;</span>;<br style="line-height: normal; " />
<span style="line-height: normal; color: rgb(76, 131, 23); ">?&gt;</span><br style="line-height: normal; " />
先运行server.php</span>&nbsp;</p><br /><br /><b>图片附件:</b><br /><a href="http://www.jackfeng.com/attachment.php?id=769" target="_blank"><img src="http://www.jackfeng.com/attachments//date_200910/cf81e505e46f54975c404674b66139e6.jpg" border="0" alt="大小: 36.03 K&#13;尺寸: 331 x 92&#13;浏览: 153 次&#13;点击打开新窗口浏览全图" width="331" height="92" /></a><br /><br /><b>图片附件:</b><br /><a href="http://www.jackfeng.com/attachment.php?id=770" target="_blank"><img src="http://www.jackfeng.com/attachments//date_200910/3645e829ba6fa51a31fa26fd2b33cb7c.jpg" border="0" alt="大小: 94.69 K&#13;尺寸: 115 x 92&#13;浏览: 157 次&#13;点击打开新窗口浏览全图" width="115" height="92" /></a>]]></description>
			<link>http://www.jackfeng.com/archives/1364/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-10-11 15:21</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1345/</guid>
			<title>eclipse 启动参数</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p>想要eclipse 速度快那这个文章必看。。</p><br /><br /><a href="http://www.jackfeng.com/archives/1345/" target="_blank">阅读全文</a><br /><br />]]></description>
			<link>http://www.jackfeng.com/archives/1345/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-04-18 09:35</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1343/</guid>
			<title>PHP 中执行排序与 MySQL 中排序</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p>肥嘟嘟介绍的一篇关于排序问题的文章：）</p>
<h4>Q：列出在 <acronym title="PHP (Personal Home Pages) Hypertext Preprocessor">PHP</acronym> 中执行排序要优于在 MYSQL 中排序的原因？给一些必须在MYSQL中排序的实例？</h4>
<h4>列出一些 <acronym title="PHP (Personal Home Pages) Hypertext Preprocessor">PHP</acronym> 中执行排序更优的情况&hellip;&hellip;</h4>
<h4>列出一些必须在 MYSQL 中排序的实例&hellip;&hellip;</h4><br /><br /><a href="http://www.jackfeng.com/archives/1343/" target="_blank">阅读全文</a><br /><br />]]></description>
			<link>http://www.jackfeng.com/archives/1343/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-04-14 00:35</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1332/</guid>
			<title>php保留小数点</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p>$n=round(1.95583, 2); <br />
这是四舍五入法保留2位小数</p>]]></description>
			<link>http://www.jackfeng.com/archives/1332/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-02-27 03:03</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1330/</guid>
			<title>将数组写入txt文件 var_export</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p>var_export($times,true);后面不加true不能写入文件哟</p>
<pre><ol class="dp-c"><li class="alt"><span><span class="vars">$fp</span><span>&nbsp;=&nbsp;</span><span class="func">fopen</span><span>(</span><span class="string">'aa.txt'</span><span>,</span><span class="string">'w+'</span><span>);&nbsp;</span></span></li><li><span>fwrite(<span class="vars">$fp</span><span>,var_export(</span><span class="vars">$times</span><span>,true));&nbsp;</span></span></li><li class="alt"><span>fclose(<span class="vars">$fp</span><span>);&nbsp;</span></span></li></ol></pre>
<p>&nbsp;</p>]]></description>
			<link>http://www.jackfeng.com/archives/1330/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-02-22 03:22</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1328/</guid>
			<title>跟我用OFC的PHP类库——x_axis_labels</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p><img src="http://www.51toria.cn/attachments/month_0812/i200812202378.jpg" alt="" /><br />
设置x_axis_labels标签稍微有些复杂，之前介绍过x_axis对象有提供过set_labels_from_array方法，是创建对象方式标签，格式：<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set_labels_from_array( $a ) //参数是一个数组定义<br />
<span style="color: rgb(153, 51, 0);">注意上面方法是x_axis对象的方法，别搞错！</span><br />
<br />
OFC提供更进一步的设置x轴标签显示的参数，就是x_axis_labels<br />
<br />
对象：x_axis_labels<br />
方法：</p>
<ul>
    <li>set_setps ( $steps )<br />
    设置每隔N(步阶)个数显示标签</li>
    <li>set_labels ( $labels )<br />
    设置标签数组</li>
    <li>set_colour ( $colour )<br />
    设置标签颜色,十六进制</li>
    <li>set_size ( $size )<br />
    标签文字大小</li>
    <li>set_vertical()<br />
    所有标签垂直显示</li>
</ul>
<p><br />
事例代码:<br />
&nbsp;</p>
<div>
<div class="dp-highlighter">
<div class="bar">&nbsp;</div>
<ol class="dp-c">
    <li class="alt"><span><span>&lt;?php &nbsp;&nbsp;</span></span></li>
    <li><span class="comment">//引用OFC类库 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="keyword">include</span><span>&nbsp;</span><span class="string">'libs\php-ofc-library\open-flash-chart.php'</span><span>; &nbsp;&nbsp;</span></li>
    <li><span class="comment">//创建标题对象并设置标题名和样式 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$title</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;title(); &nbsp;&nbsp;</span></li>
    <li><span class="vars">$title</span><span>-&gt;text&nbsp;=&nbsp;</span><span class="string">&quot;0758jian&quot;</span><span>; &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$title</span><span>-&gt;set_style(</span><span class="string">&quot;font-size:&nbsp;20px;&nbsp;color:#0000ff;&nbsp;font-family:&nbsp;Verdana;&nbsp;text-align:&nbsp;center;&quot;</span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="comment">//创建line_dot对象，日后再讲解,写上去是方便查看x轴 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$line_dot</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;line_dot(); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$line_dot</span><span>-&gt;set_values(&nbsp;</span><span class="keyword">array</span><span>(9,8,7,6,5,4,3,2,1)&nbsp;); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="comment">//创建x轴对象 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$x</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;x_axis(); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$x</span><span>-&gt;set_colour(&nbsp;</span><span class="string">'#D7E4A3'</span><span>&nbsp;);&nbsp;</span><span class="comment">//x轴线颜色 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$x</span><span>-&gt;set_grid_colour(&nbsp;</span><span class="string">'#A2ACBA'</span><span>&nbsp;);&nbsp;</span><span class="comment">//单元格边颜色(也就是竖线) </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;</span></li>
    <li><span class="comment">//创建x_axis_labels对象 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$x_labels</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;x_axis_labels(); &nbsp;&nbsp;</span></li>
    <li><span class="vars">$x_labels</span><span>-&gt;set_steps(&nbsp;2&nbsp;);&nbsp;</span><span class="comment">//设置每隔N(步阶)个数显示标签 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="comment">//设置标签数组(注与x_axis的set_labels是一样的只不过JSON以数组或者对象表示) </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$x_labels</span><span>-&gt;set_labels( &nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">array</span><span>(&nbsp;</span><span class="string">'one'</span><span>,</span><span class="string">'two'</span><span>,</span><span class="string">'three'</span><span>,</span><span class="string">'four'</span><span>,</span><span class="string">'five'</span><span>,</span><span class="string">'six'</span><span>,</span><span class="string">'seven'</span><span>,</span><span class="string">'eight'</span><span>,</span><span class="string">'nine'</span><span>&nbsp;) &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$x_labels</span><span>-&gt;set_colour(&nbsp;</span><span class="string">'#CF4D5F'</span><span>&nbsp;);&nbsp;</span><span class="comment">//设置标签颜色,十六进制 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$x_labels</span><span>-&gt;set_size(&nbsp;16&nbsp;);&nbsp;</span><span class="comment">//标签文字大小 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$x_labels</span><span>-&gt;set_vertical();&nbsp;</span><span class="comment">//设置标签为垂直方向 </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="comment">//把x_labels对象的内容转给x_axis对象 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$x</span><span>-&gt;set_labels(&nbsp;</span><span class="vars">$x_labels</span><span>); &nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;</span></li>
    <li><span class="comment">//创建OFC对象并应用标题和输出JSON格式 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$chart</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;open_flash_chart(); &nbsp;&nbsp;</span></li>
    <li><span class="vars">$chart</span><span>-&gt;set_title(</span><span class="vars">$title</span><span>); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$chart</span><span>-&gt;set_x_axis(</span><span class="vars">$x</span><span>);&nbsp;</span><span class="comment">//调用设置set_x_axis方法 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$chart</span><span>-&gt;add_element(&nbsp;</span><span class="vars">$line_dot</span><span>&nbsp;); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="func">echo</span><span>&nbsp;</span><span class="vars">$chart</span><span>-&gt;toString(); &nbsp;&nbsp;</span></li>
    <li><span>?&gt;&nbsp;&nbsp;</span></li>
</ol>
</div>
<link rel="stylesheet" type="text/css" href="http://www.51toria.cn/fckeditor/editor/plugins/highlighter/dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css" /></div>
<p>效果演示:<br />
<script src="http://www.51toria.cn/js/swfobject.js" type="text/javascript"></script>
<script type="text/javascript">
swfobject.embedSWF(
          "open-flash-chart.swf", "phpclassXaxisLabels",
          "500px", "280px", "9.0.0", "",
		  {"data-file":"demo/openflashchart/phpclassXaxisLabels.php","loading":"正在下载..."}
        );
</script>
</p>
<object height="280" width="500" type="application/x-shockwave-flash" data="open-flash-chart.swf" id="phpclassXaxisLabels" style="visibility: visible;">
<param name="flashvars" value="data-file=demo/openflashchart/phpclassXaxisLabels.php&amp;loading=正在下载..." /></object>
<p>&nbsp;</p>
<p><br />
<a href="http://www.51toria.cn/demo/openflashchart/phpclassXaxisLabels.php" target="_blank">点击查看PHP输出的格式</a><br />
<br />
更为细节的设置x轴标签对象x_axis_label，<span style="color: rgb(153, 51, 0);"><span style="background-color: rgb(255, 255, 153);">注意和上面所说的x_axis_labels就一个s区别<br />
</span></span><span><span>对象：x_axis_label($text, $colour, $size, $rotate)<br />
参数依次是标签名、标签颜色、标签大小、旋转方式(&quot;vertical&quot; &quot;diaganol&quot; or &quot;horizontal&quot; )<br />
<br />
方法：<br />
</span></span></p>
<ul>
    <li>set_text( $text ) <br />
    设置标签名</li>
    <li><span><span>set_colour( $colour ) <br />
    标签颜色</span></span></li>
    <li><span><span>set_size( $size ) <br />
    标签大小</span></span></li>
    <li><span><span>set_rotate( $rotate ) <br />
    旋转角度</span></span></li>
    <li><span><span>set_vertical()<br />
    设置垂直方式</span></span></li>
    <li><span><span>set_visible()<br />
    设置可视</span></span></li>
</ul>
<p><span><span><br />
事例代码:<br />
</span></span></p>
<div>
<div class="dp-highlighter">
<div class="bar">&nbsp;</div>
<ol class="dp-c">
    <li class="alt"><span><span>&lt;?php &nbsp;&nbsp;</span></span></li>
    <li><span class="comment">//引用OFC类库 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="keyword">include</span><span>&nbsp;</span><span class="string">'libs\php-ofc-library\open-flash-chart.php'</span><span>; &nbsp;&nbsp;</span></li>
    <li><span class="comment">//创建标题对象并设置标题名和样式 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$title</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;title(); &nbsp;&nbsp;</span></li>
    <li><span class="vars">$title</span><span>-&gt;text&nbsp;=&nbsp;</span><span class="string">&quot;0758jian&quot;</span><span>; &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$title</span><span>-&gt;set_style(</span><span class="string">&quot;font-size:&nbsp;20px;&nbsp;color:#0000ff;&nbsp;font-family:&nbsp;Verdana;&nbsp;text-align:&nbsp;center;&quot;</span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="comment">//创建line_dot对象，日后再讲解,写上去是方便查看x轴 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$line_dot</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;line_dot(); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$line_dot</span><span>-&gt;set_values(&nbsp;</span><span class="keyword">array</span><span>(9,8,7,6,5,4,3,2,1)&nbsp;); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="comment">//创建x轴对象 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$x</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;x_axis(); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$x</span><span>-&gt;set_colour(&nbsp;</span><span class="string">'#D7E4A3'</span><span>&nbsp;);&nbsp;</span><span class="comment">//x轴线颜色 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$x</span><span>-&gt;set_grid_colour(&nbsp;</span><span class="string">'#A2ACBA'</span><span>&nbsp;);&nbsp;</span><span class="comment">//单元格边颜色(也就是竖线) </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$x</span><span>-&gt;set_steps(&nbsp;1&nbsp;); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="comment">//创建x_axis_labels对象 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$x_labels</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;x_axis_labels(); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$x_labels</span><span>-&gt;set_steps(&nbsp;2&nbsp;);&nbsp;</span><span class="comment">//设置每隔N(步阶)个数显示标签 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$x_labels</span><span>-&gt;set_colour(&nbsp;</span><span class="string">'#CF4D5F'</span><span>&nbsp;);&nbsp;</span><span class="comment">//设置标签颜色,十六进制 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$x_labels</span><span>-&gt;set_size(&nbsp;16&nbsp;);&nbsp;</span><span class="comment">//标签文字大小 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$x_labels</span><span>-&gt;set_vertical();&nbsp;</span><span class="comment">//设置标签为垂直方向 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$tmp</span><span>&nbsp;=&nbsp;</span><span class="keyword">array</span><span>(); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$tmp</span><span>[]&nbsp;=&nbsp;</span><span class="string">'2008-03'</span><span>; &nbsp;&nbsp;</span></li>
    <li><span class="vars">$tmp</span><span>[]&nbsp;=&nbsp;</span><span class="string">'2008-04'</span><span>; &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$tmp</span><span>[]&nbsp;=&nbsp;</span><span class="string">'2008-05'</span><span>; &nbsp;&nbsp;</span></li>
    <li><span class="vars">$tmp</span><span>[]&nbsp;=&nbsp;</span><span class="string">'2008-06'</span><span>; &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$tmp</span><span>[]&nbsp;=&nbsp;&nbsp;</span><span class="keyword">new</span><span>&nbsp;x_axis_label(</span><span class="string">'2008-07'</span><span>,&nbsp;</span><span class="string">'#CF4D5F'</span><span>,&nbsp;16,&nbsp;315); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$tmp</span><span>[]&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;x_axis_label(</span><span class="string">'2008-08'</span><span>,&nbsp;</span><span class="string">'#0000FF'</span><span>,&nbsp;20,&nbsp;</span><span class="string">'vertical'</span><span>); &nbsp;&nbsp;</span></li>
    <li><span class="vars">$tmp</span><span>[]&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;x_axis_label(</span><span class="string">'2008-09'</span><span>,&nbsp;</span><span class="string">'#0000FF'</span><span>,&nbsp;30,&nbsp;</span><span class="string">'vertical'</span><span>); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$eight</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;x_axis_label(</span><span class="string">'2008-10'</span><span>,&nbsp;</span><span class="string">'#00FF00'</span><span>,&nbsp;16,&nbsp;</span><span class="string">'diagonal'</span><span>);&nbsp;</span><span class="comment">//注意这里原本是不可视的 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$eight</span><span>-&gt;set_visible();&nbsp;</span><span class="comment">//这里强迫设置可视 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$tmp</span><span>[]&nbsp;=&nbsp;</span><span class="vars">$eight</span><span>; &nbsp;&nbsp;</span></li>
    <li><span class="vars">$tmp</span><span>[]&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;x_axis_label(</span><span class="string">'2008-11'</span><span>,&nbsp;</span><span class="string">'#FF00FF'</span><span>,&nbsp;16,&nbsp;</span><span class="string">'horizontal'</span><span>); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$ten</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;x_axis_label(null,null,null,null); &nbsp;&nbsp;</span></li>
    <li><span class="vars">$ten</span><span>-&gt;set_text(&nbsp;</span><span class="string">'2008-12'</span><span>&nbsp;); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$ten</span><span>-&gt;set_colour(</span><span class="string">'#999900'</span><span>); &nbsp;&nbsp;</span></li>
    <li><span class="vars">$ten</span><span>-&gt;set_size(12); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$ten</span><span>-&gt;set_rotate(&nbsp;315&nbsp;); &nbsp;&nbsp;</span></li>
    <li><span class="comment">//$ten-&gt;set_vertical(); </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$ten</span><span>-&gt;set_visible(); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$tmp</span><span>[]&nbsp;=&nbsp;</span><span class="vars">$ten</span><span>; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="comment">//把$tmp数组传给x_axis_labels对象 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$x_labels</span><span>-&gt;set_labels(&nbsp;</span><span class="vars">$tmp</span><span>&nbsp;); &nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;</span></li>
    <li><span class="comment">//把x_labels对象的内容转给x_axis对象 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$x</span><span>-&gt;set_labels(&nbsp;</span><span class="vars">$x_labels</span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="comment">//创建OFC对象并应用标题和输出JSON格式 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$chart</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;open_flash_chart(); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$chart</span><span>-&gt;set_title(</span><span class="vars">$title</span><span>); &nbsp;&nbsp;</span></li>
    <li><span class="vars">$chart</span><span>-&gt;set_x_axis(</span><span class="vars">$x</span><span>);&nbsp;</span><span class="comment">//调用设置set_x_axis方法 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$chart</span><span>-&gt;add_element(&nbsp;</span><span class="vars">$line_dot</span><span>&nbsp;); &nbsp;&nbsp;</span></li>
    <li><span class="func">echo</span><span>&nbsp;</span><span class="vars">$chart</span><span>-&gt;toString(); &nbsp;&nbsp;</span></li>
    <li class="alt"><span>?&gt; &nbsp;&nbsp;</span></li>
</ol>
</div>
<link rel="stylesheet" type="text/css" href="http://www.51toria.cn/fckeditor/editor/plugins/highlighter/dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css" /></div>
<div><span><span><br />
<br />
效果演示:<br />
<script type="text/javascript">
swfobject.embedSWF(
          "open-flash-chart.swf", "phpclassXaxisLabels2",
          "500px", "280px", "9.0.0", "",
		  {"data-file":"demo/openflashchart/phpclassXaxisLabels2.php","loading":"正在下载..."}
        );
</script>
</span></span></div>
<object height="280" width="500" type="application/x-shockwave-flash" data="open-flash-chart.swf" id="phpclassXaxisLabels2" style="visibility: visible;">
<param name="flashvars" value="data-file=demo/openflashchart/phpclassXaxisLabels2.php&amp;loading=正在下载..." /></object>
<p>&nbsp;</p>
<p><br />
<a href="http://www.51toria.cn/demo/openflashchart/phpclassXaxisLabels2.php" target="_blank">点击查看PHP输出的格式</a></p>
<p>&nbsp;</p>
<p>转自http://www.51toria.cn/article.asp?id=137</p>]]></description>
			<link>http://www.jackfeng.com/archives/1328/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-02-12 00:48</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1327/</guid>
			<title>跟我用OFC的PHP类库——y_axis</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p><img src="http://www.51toria.cn/attachments/month_0812/l2008121802320.jpg" alt="" /><br />
<br />
对象：y_axis</p>
<ul>
    <li>set_stroke( $s )<br />
    y轴线宽度</li>
    <li>set_tick_length( $val ) <br />
    y轴刻度长度</li>
    <li>set_colours( $colour, $grid_colour ) <br />
    y轴线颜色与单元格颜色(即横线)</li>
    <li>set_colour( $colour ) <br />
    y轴线颜色</li>
    <li>set_grid_colour( $colour ) <br />
    单元格颜色(即横线)</li>
    <li>set_range( $min, $max, $steps=1 )<br />
    刻度范围值，参数分别是最小值、最大值和步阶</li>
    <li>set_offset( $off )<br />
    如果是真值，就y轴从一小部分距离开始</li>
    <li>set_labels( $labels )<br />
    设置y轴标签名,这会取代set_range的方法</li>
    <li>set_steps( $steps )<br />
    设置步阶</li>
</ul>
<p><br />
事例代码:<br />
&nbsp;</p>
<div>
<div class="dp-highlighter">
<div class="bar">&nbsp;</div>
<ol class="dp-c">
    <li class="alt"><span><span>&lt;?php &nbsp;&nbsp;</span></span></li>
    <li><span class="comment">//引用OFC类库 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="keyword">include</span><span>&nbsp;</span><span class="string">'libs\php-ofc-library\open-flash-chart.php'</span><span>; &nbsp;&nbsp;</span></li>
    <li><span class="comment">//创建标题对象并设置标题名和样式 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$title</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;title(); &nbsp;&nbsp;</span></li>
    <li><span class="vars">$title</span><span>-&gt;text&nbsp;=&nbsp;</span><span class="string">&quot;0758jian&quot;</span><span>; &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$title</span><span>-&gt;set_style(</span><span class="string">&quot;font-size:&nbsp;20px;&nbsp;color:#0000ff;&nbsp;font-family:&nbsp;Verdana;&nbsp;text-align:&nbsp;center;&quot;</span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="comment">//创建y轴对象 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$y</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;y_axis();&nbsp; &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$y</span><span>-&gt;set_stroke(&nbsp;10&nbsp;);&nbsp;</span><span class="comment">//y轴线宽度 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$y</span><span>-&gt;set_tick_length(&nbsp;20&nbsp;);&nbsp;</span><span class="comment">//y轴刻度长度 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$y</span><span>-&gt;set_colours(&nbsp;</span><span class="string">'#D7E4A3'</span><span>,&nbsp;</span><span class="string">'#A2ACBA'</span><span>);&nbsp;</span><span class="comment">//y轴线颜色与单元格颜色(即横线) </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="comment">//$y-&gt;set_colour(&nbsp;'#D7E4A3'&nbsp;);&nbsp;//y轴线颜色 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="comment">//$y-&gt;set_grid_colour(&nbsp;'#A2ACBA'&nbsp;);&nbsp;//单元格颜色(即横线) </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="comment">//$y-&gt;set_range(&nbsp;0,&nbsp;9,&nbsp;1&nbsp;);&nbsp;//刻度范围值，参数分别是最小值、最大值和步阶 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$y</span><span>-&gt;set_offset(true);&nbsp;</span><span class="comment">//如果是真值，就y轴从一小部分距离开始 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$y</span><span>-&gt;set_labels(&nbsp;</span><span class="keyword">array</span><span>(</span><span class="string">'Zero'</span><span>,</span><span class="string">'One'</span><span>,</span><span class="string">'Two'</span><span>,</span><span class="string">'Three'</span><span>,</span><span class="string">'Four'</span><span>,</span><span class="string">'Five'</span><span>,</span><span class="string">'Six'</span><span>,</span><span class="string">'Seven'</span><span>,</span><span class="string">'Eight'</span><span>)&nbsp;);&nbsp;</span><span class="comment">//设置y轴标签名 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$y</span><span>-&gt;set_steps(&nbsp;1&nbsp;);&nbsp;</span><span class="comment">//设置步阶 </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="comment">//创建OFC对象并应用标题和输出JSON格式 </span><span>&nbsp;&nbsp;</span></li>
    <li><span class="vars">$chart</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;open_flash_chart(); &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="vars">$chart</span><span>-&gt;set_title(</span><span class="vars">$title</span><span>); &nbsp;&nbsp;</span></li>
    <li><span class="vars">$chart</span><span>-&gt;set_y_axis(</span><span class="vars">$y</span><span>);&nbsp;</span><span class="comment">//调用设置set_y_axis方法 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span class="func">echo</span><span>&nbsp;</span><span class="vars">$chart</span><span>-&gt;toString(); &nbsp;&nbsp;</span></li>
    <li><span>?&gt;&nbsp;&nbsp;</span></li>
</ol>
</div>
<link rel="stylesheet" type="text/css" href="http://www.51toria.cn/fckeditor/editor/plugins/highlighter/dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css" /></div>
<p><span style="background-color: rgb(255, 255, 153);"><span style="color: rgb(153, 51, 0);">注意:y_axis默认位置是在左边，想设置在右边就要用与它有相同方法的另一个对象是y_axis_right，它们的方法一致！还有注意一些方法的重合性</span></span><br />
<br />
效果演示:<br />
<script src="http://www.51toria.cn/js/swfobject.js" type="text/javascript"></script>
<script type="text/javascript">
swfobject.embedSWF(
          "open-flash-chart.swf", "phpclassyaxis1",
          "500px", "280px", "9.0.0", "",
		  {"data-file":"demo/openflashchart/phpclassyaxis.php?flag=1","loading":"正在下载..."}
        );
swfobject.embedSWF(
          "open-flash-chart.swf", "phpclassyaxis2",
          "500px", "280px", "9.0.0", "",
		  {"data-file":"demo/openflashchart/phpclassyaxis.php?flag=2","loading":"正在下载..."}
        );
swfobject.embedSWF(
          "open-flash-chart.swf", "phpclassyaxis3",
          "500px", "280px", "9.0.0", "",
		  {"data-file":"demo/openflashchart/phpclassyaxis.php?flag=3","loading":"正在下载..."}
        );
</script>
</p>
<object height="280" width="500" type="application/x-shockwave-flash" data="open-flash-chart.swf" id="phpclassyaxis1" style="visibility: visible;">
<param name="flashvars" value="data-file=demo/openflashchart/phpclassyaxis.php?flag=1&amp;loading=正在下载..." /></object>
<p><br />
正负y轴:<br />
&nbsp;</p>
<object height="280" width="500" type="application/x-shockwave-flash" data="open-flash-chart.swf" id="phpclassyaxis2" style="visibility: visible;">
<param name="flashvars" value="data-file=demo/openflashchart/phpclassyaxis.php?flag=2&amp;loading=正在下载..." /></object>
<p><br />
右边y轴:<br />
&nbsp;</p>
<object height="280" width="500" type="application/x-shockwave-flash" data="open-flash-chart.swf" id="phpclassyaxis3" style="visibility: visible;">
<param name="flashvars" value="data-file=demo/openflashchart/phpclassyaxis.php?flag=3&amp;loading=正在下载..." /></object>
<p><br />
<a href="http://www.51toria.cn/demo/openflashchart/phpclassYaxis.php?flag=1" target="_blank">点击查看PHP输出的格式</a><br />
<a href="http://www.51toria.cn/demo/openflashchart/phpclassYaxis.php?flag=2" target="_blank">点击查看Y轴正负值格式</a><br />
<a href="http://www.51toria.cn/demo/openflashchart/phpclassYaxis.php?flag=3" target="_blank">点击查看Y轴右边格式</a></p>
<p>转自http://www.51toria.cn/article.asp?id=134</p>]]></description>
			<link>http://www.jackfeng.com/archives/1327/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-02-12 00:46</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1324/</guid>
			<title>php 给不足的前面加0</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p>str_pad($i,2,'0',STR_PAD_LEFT)</p>]]></description>
			<link>http://www.jackfeng.com/archives/1324/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-02-06 01:48</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1321/</guid>
			<title>查找是否包含字符串</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p><span style="font-size: small;">&lt;?php<br />
$mystring = 'abc';<br />
$findme&nbsp;&nbsp; = 'a';<br />
$pos = strpos($mystring, $findme);<br />
<br />
// Note our use of ===.&nbsp; Simply == would not work as expected<br />
// because the position of 'a' was the 0th (first) character.<br />
if ($pos === false) {<br />
&nbsp;&nbsp; echo &quot;The string '$findme' was not found in the string '$mystring'&quot;;<br />
} else {<br />
&nbsp;&nbsp; echo &quot;The string '$findme' was found in the string '$mystring'&quot;;<br />
&nbsp;&nbsp; echo &quot; and exists at position $pos&quot;;<br />
}<br />
<br />
// We can search for the character, ignoring anything before the offset<br />
$newstring = 'abcdef abcdef';<br />
$pos = strpos($newstring, 'a', 1); // $pos = 7, not 0<br />
?&gt;</span></p>
<p>&nbsp;</p>]]></description>
			<link>http://www.jackfeng.com/archives/1321/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-02-02 00:59</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1319/</guid>
			<title>PHP 异常处理</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p><strong>异常（Exception）用于在指定的错误发生时改变脚本的正常流程。</strong></p><br /><br /><a href="http://www.jackfeng.com/archives/1319/" target="_blank">阅读全文</a><br /><br />]]></description>
			<link>http://www.jackfeng.com/archives/1319/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-01-31 12:30</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1317/</guid>
			<title>PHP字符串替换函数 strtr 浅谈</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p>原文出处 http://blog.asdjkl.net/archives/8<br />
</p>
<div class="entry">
<p>先来看看这个php字符串替换函数 strtr()的两种状态</p>
<p>strtr(string,from,to)<br />
或者strtr(string,array)</p>
<p>首先针对strtr函数第一种方式<br />
我们看看下面的举例:</p>
<div class="wp_syntax">
<table>
    <tbody>
        <tr>
            <td class="line_numbers">
            <pre>
1
2
3</pre>
            </td>
            <td class="code">
            <pre class="php"><span style="color: rgb(0, 0, 0); font-weight: bold;">&lt;?php</span>
<span style="color: rgb(0, 0, 102);">echo</span> <span style="color: rgb(0, 0, 102);">strtr</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">&quot;I Love you&quot;</span><span style="color: rgb(102, 204, 102);">,</span><span style="color: rgb(255, 0, 0);">&quot;Lo&quot;</span><span style="color: rgb(102, 204, 102);">,</span><span style="color: rgb(255, 0, 0);">&quot;lO&quot;</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(0, 0, 0); font-weight: bold;">?&gt;</span></pre>
            </td>
        </tr>
    </tbody>
</table>
</div>
<p>得到的结果是</p>
<div class="wp_syntax">
<table>
    <tbody>
        <tr>
            <td class="line_numbers">
            <pre>
1</pre>
            </td>
            <td class="code">
            <pre class="php">
I lOve yOu</pre>
            </td>
        </tr>
    </tbody>
</table>
</div>
<p>这个结果提醒我们<br />
1.strtr它是区分大小写的<br />
2.strtr的替换是很特殊的，你注意看后面那个yOu，中间的O被替换的，这显然不是我们的本意</p>
<p>再举一个特殊例子，说明这个php sttr函数的怪异</p>
<div class="wp_syntax">
<table>
    <tbody>
        <tr>
            <td class="line_numbers">
            <pre>
1
2
3</pre>
            </td>
            <td class="code">
            <pre class="php"><span style="color: rgb(0, 0, 0); font-weight: bold;">&lt;?php</span>
<span style="color: rgb(0, 0, 102);">echo</span> <span style="color: rgb(0, 0, 102);">strtr</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">&quot;I Love you&quot;</span><span style="color: rgb(102, 204, 102);">,</span><span style="color: rgb(255, 0, 0);">&quot;Love&quot;</span><span style="color: rgb(102, 204, 102);">,</span><span style="color: rgb(255, 0, 0);">&quot;&quot;</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(0, 0, 0); font-weight: bold;">?&gt;</span></pre>
            </td>
        </tr>
    </tbody>
</table>
</div>
<p>结果是</p>
<div class="wp_syntax">
<table>
    <tbody>
        <tr>
            <td class="line_numbers">
            <pre>
1</pre>
            </td>
            <td class="code">
            <pre class="php">
I Love you</pre>
            </td>
        </tr>
    </tbody>
</table>
</div>
<p>什么也不会改变，所以strtr需要注意的是:<br />
3.不能被替换为空，也就是末位那个参数不能是空字符串，当然空格是可以的。</p>
<p>再次举例strtr函数的另一种情况</p>
<div class="wp_syntax">
<table>
    <tbody>
        <tr>
            <td class="line_numbers">
            <pre>
1
2
3</pre>
            </td>
            <td class="code">
            <pre class="php"><span style="color: rgb(0, 0, 0); font-weight: bold;">&lt;?php</span>
<span style="color: rgb(0, 0, 102);">echo</span> <span style="color: rgb(0, 0, 102);">strtr</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">&quot;I Loves you&quot;</span><span style="color: rgb(102, 204, 102);">,</span><span style="color: rgb(255, 0, 0);">&quot;Love&quot;</span><span style="color: rgb(102, 204, 102);">,</span><span style="color: rgb(255, 0, 0);">&quot;lOvEA&quot;</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(0, 0, 0); font-weight: bold;">?&gt;</span></pre>
            </td>
        </tr>
    </tbody>
</table>
</div>
<p>结果是</p>
<div class="wp_syntax">
<table>
    <tbody>
        <tr>
            <td class="line_numbers">
            <pre>
1</pre>
            </td>
            <td class="code">
            <pre class="php">
I lOvEs yOu</pre>
            </td>
        </tr>
    </tbody>
</table>
</div>
<p>注意看第三个参数的A，在结果中并没有出现<br />
4.我不建议用strtr以少换多</p>
<p>ok，既然这个strtr函数挺麻烦为什么还要用呢？<br />
原因是，它的速度很快<br />
据说，strtr 比 str_replace 快四倍<br />
所以<br />
5.能用strtr函数的时候一定要用</p>
<p>那怎么用才舒服？<br />
这就是它的第二种情况<br />
strtr(string,array)<br />
6.strtr符合意愿的使用方法</p>
<div class="wp_syntax">
<table>
    <tbody>
        <tr>
            <td class="line_numbers">
            <pre>
1
2
3
4</pre>
            </td>
            <td class="code">
            <pre class="php"><span style="color: rgb(0, 0, 0); font-weight: bold;">&lt;?php</span>
<span style="color: rgb(255, 0, 0);">$table_change</span> <span style="color: rgb(102, 204, 102);">=</span> <span style="color: rgb(0, 0, 102);">array</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">'you'</span><span style="color: rgb(102, 204, 102);">=&gt;</span><span style="color: rgb(255, 0, 0);">'her sister'</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(0, 0, 102);">echo</span> <span style="color: rgb(0, 0, 102);">strtr</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">&quot;I Love you&quot;</span><span style="color: rgb(102, 204, 102);">,</span><span style="color: rgb(255, 0, 0);">$table_change</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(0, 0, 0); font-weight: bold;">?&gt;</span></pre>
            </td>
        </tr>
    </tbody>
</table>
</div>
<p>结果为<br />
I Love her sister</p>
<p>7.小技巧：你想到替换什么你就往数组加什么<br />
比如</p>
<div class="wp_syntax">
<table>
    <tbody>
        <tr>
            <td class="line_numbers">
            <pre>
1
2
3
4
5</pre>
            </td>
            <td class="code">
            <pre class="php"><span style="color: rgb(0, 0, 0); font-weight: bold;">&lt;?php</span>
<span style="color: rgb(255, 0, 0);">$table_change</span> <span style="color: rgb(102, 204, 102);">=</span> <span style="color: rgb(0, 0, 102);">array</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">'you'</span><span style="color: rgb(102, 204, 102);">=&gt;</span><span style="color: rgb(255, 0, 0);">'her sister'</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(255, 0, 0);">$table_change</span> <span style="color: rgb(102, 204, 102);">+=</span> <span style="color: rgb(0, 0, 102);">array</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">'Love'</span> <span style="color: rgb(102, 204, 102);">=&gt;</span> <span style="color: rgb(255, 0, 0);">'hate'</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(0, 0, 102);">echo</span> <span style="color: rgb(0, 0, 102);">strtr</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">&quot;I Love you&quot;</span><span style="color: rgb(102, 204, 102);">,</span><span style="color: rgb(255, 0, 0);">$table_change</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(0, 0, 0); font-weight: bold;">?&gt;</span></pre>
            </td>
        </tr>
    </tbody>
</table>
</div>
<p>结果是<br />
I hate her sister</p>
<p>再次提醒那个Love 写成love 是行不通的哦。</p>
<p>ok，乱七八糟说了一通，其实关于strtr最想说的就是这个后面的用法了<br />
简单方便。<br />
貌似后面的用法也忽略掉了前后字符长度不同的问题</p>
<p>以上php strtr函数实验，PHP5.2 测试通过。</p>
</div>]]></description>
			<link>http://www.jackfeng.com/archives/1317/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-01-18 12:39</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1316/</guid>
			<title>相当好的smarty文章 功能俱全啊</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p>N多smarty范例 先抓进来了</p><br /><br /><a href="http://www.jackfeng.com/archives/1316/" target="_blank">阅读全文</a><br /><br />]]></description>
			<link>http://www.jackfeng.com/archives/1316/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-01-18 03:19</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1315/</guid>
			<title>相当不错的phpmailer 乱码</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p>&nbsp; $mail = new PHPMailer(); <br />
&nbsp;&nbsp;$mail-&gt;CharSet = &quot;GB2312&quot;; // 设置字符集编码 utf-8<br />
&nbsp;&nbsp;$mail-&gt;Encoding = &quot;base64&quot;;//设置文本编码方式</p>]]></description>
			<link>http://www.jackfeng.com/archives/1315/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-01-17 22:02</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1314/</guid>
			<title>php判断Email,Url,手机号码 合法性</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p><br />
1. 判断<a title="Posts tagged with email" rel="tag" class="st_tag internal_tag" href="http://www.ruofeel.cn/tag/email">Email</a>:</p>
<div class="hl-surround">
<div class="hl-main"><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"><br />
</span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">is_email</span><span style="color: Olive;">(</span><span style="color: rgb(0, 0, 139);">$email</span><span style="color: Olive;">){</span><span style="color: Gray;"><br />
</span><span style="color: Green;">return</span><span style="color: Gray;"> </span><span style="color: Blue;">strlen</span><span style="color: Olive;">(</span><span style="color: rgb(0, 0, 139);">$email</span><span style="color: Olive;">)</span><span style="color: Gray;"> &gt; </span><span style="color: Maroon;">6</span><span style="color: Gray;"> &amp;&amp; </span><span style="color: Blue;">preg_match</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">&quot;</span><span style="color: Red;">/^[\w\-\.]+@[\w\-]+(\.\w+)+$/</span><span style="color: rgb(139, 0, 0);">&quot;</span><span style="color: Gray;">, </span><span style="color: rgb(0, 0, 139);">$email</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />
</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />
</span><span style="color: Blue;">?&gt;</span></div>
</div>
<p>2. 判断<a title="Posts tagged with url" rel="tag" class="st_tag internal_tag" href="http://www.ruofeel.cn/tag/url">Url</a>:</p>
<div class="hl-surround">
<div class="hl-main"><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">is_url</span><span style="color: Olive;">(</span><span style="color: rgb(0, 0, 139);">$str</span><span style="color: Olive;">){</span><span style="color: Gray;"><br />
&nbsp; </span><span style="color: Green;">return</span><span style="color: Gray;"> </span><span style="color: Blue;">preg_match</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">&quot;</span><span style="color: Red;">/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&amp;_~`@[\]</span><span style="color: Navy;">\'</span><span style="color: Red;">:+!]*([^&lt;&gt;</span><span style="color: Navy;">\&quot;</span><span style="color: Red;">])*$/</span><span style="color: rgb(139, 0, 0);">&quot;</span><span style="color: Gray;">, </span><span style="color: rgb(0, 0, 139);">$str</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />
&nbsp;</span><span style="color: Olive;">}</span></div>
</div>
<p>3. 判断手机号码:</p>
<div class="hl-surround">
<div class="hl-main"><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">is_mobile</span><span style="color: Olive;">(</span><span style="color: rgb(0, 0, 139);">$str</span><span style="color: Olive;">){</span><span style="color: Gray;"><br />
&nbsp; </span><span style="color: Green;">return</span><span style="color: Gray;"> </span><span style="color: Blue;">preg_match</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">&quot;</span><span style="color: Red;">/^((\(\d{3}\))|(\d{3}\-))?13\d{9}$/</span><span style="color: rgb(139, 0, 0);">&quot;</span><span style="color: Gray;">, </span><span style="color: rgb(0, 0, 139);">$str</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />
&nbsp;</span><span style="color: Olive;">}</span></div>
</div>]]></description>
			<link>http://www.jackfeng.com/archives/1314/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2009-01-15 15:17</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1304/</guid>
			<title>addslashes与mysql_escape_string的区别</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p style="text-align: left;"><span style="font-size: large;">mysql_escape_string与addslashes的区别在于 &nbsp; <br />
mysql_escape_string总是将&ldquo;<span style="color: rgb(255, 0, 0);">'</span>&rdquo;转换成&ldquo;<span style="color: rgb(255, 0, 0);">\'</span>&rdquo; &nbsp;  <br />
<br />
而addslashes &nbsp; <br />
在magic_quotes_sybase=on时将&ldquo;<span style="color: rgb(255, 0, 0);">'</span>&rdquo;转换成&ldquo;<span style="color: rgb(255, 0, 0);">''</span>&rdquo; &nbsp; <br />
在magic_quotes_sybase=off时将&ldquo;<span style="color: rgb(255, 0, 0);">'</span>&rdquo;转换成&ldquo;<span style="color: rgb(255, 0, 0);">\'</span>&rdquo; </span></p>]]></description>
			<link>http://www.jackfeng.com/archives/1304/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2008-12-27 02:19</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1298/</guid>
			<title>Wrong permissions on configuration file, should not be world writable!</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <div class="entry-content">
<p>试用的自配服务器（php+mysql+nginx）</p>
<p>在网页形式下浏览数据库时</p>
<p>出现错误：Wrong permissions on configuration file, should not be world writable!</p>
<p>其实这个错误是mysql数据库的权限设置成了777所造成的</p>
<p>解决办法就是把数据库的根目录权限重新设置成755即可</p>
<p>比如数据库 phpMyAdmin的存放目录是：/opt/ppt/phpMyAdmin</p>
<p>则可以进行如下的操作：chmod -R 755 phpMyAdmin,这样重新设置后就可以了:-)</p>
</div>]]></description>
			<link>http://www.jackfeng.com/archives/1298/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2008-12-20 11:42</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1295/</guid>
			<title>PHP实现长连接</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p>&nbsp;</p>
<pre><ol class="dp-c"><li class="alt"><span><span>&lt;?php &nbsp;</span></span></li><li><span>set_time_limit(0); &nbsp;</span></li><li class="alt"><span>header(</span><span class="string">&quot;Connection:&nbsp;Keep-Alive&quot;</span><span>); &nbsp;</span></li><li><span>header(</span><span class="string">&quot;Proxy-Connection:&nbsp;Keep-Alive&quot;</span><span>); &nbsp;</span></li><li class="alt"><span class="keyword">for</span><span>(</span><span class="vars">$i</span><span>=0;&nbsp;</span><span class="vars">$i</span><span>&lt;1000;&nbsp;</span><span class="vars">$i</span><span>++)&nbsp;{ &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;print&nbsp;</span><span class="string">'fuck&nbsp;man!'</span><span>.</span><span class="vars">$i</span><span>.</span><span class="string">'&lt;br&gt;'</span><span>; &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;</span><span class="func">flush</span><span>(); &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;sleep(3); &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;clearstatcache(); &nbsp;</span></li><li><span>} &nbsp;</span></li><li class="alt"><span>?&gt;&nbsp;</span></li></ol></pre>
<p>&nbsp;</p>]]></description>
			<link>http://www.jackfeng.com/archives/1295/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2008-12-16 20:37</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1294/</guid>
			<title>php数组弹出最后一个</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p>array_pop($GAMES)</p>
<p>这样就能把$GAMES里面的最后一个数组给弹显出来</p>
<p>然后$GAMES里面的内容就少了一个</p>]]></description>
			<link>http://www.jackfeng.com/archives/1294/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2008-12-16 11:05</pubDate>
		</item>
		<item>
			<guid>http://www.jackfeng.com/archives/1292/</guid>
			<title>php 保留小数</title>
			<author>小锋</author>
			<description><![CDATA[小锋堂 ( http://www.jackfeng.com/ ) : <p>$n=round(1.95583, 2); 保留两位小数+四舍五入</p>]]></description>
			<link>http://www.jackfeng.com/archives/1292/</link>
			<category domain="http://www.jackfeng.com/category/16/">PHP</category>
			<pubDate>2008-12-14 11:24</pubDate>
		</item>
	</channel>
</rss>
