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

<channel>
	<title>蓝色的华 &#187; php</title>
	<atom:link href="http://bluehua.org/category/php/feed" rel="self" type="application/rss+xml" />
	<link>http://bluehua.org</link>
	<description>分享所学,backup一切~</description>
	<lastBuildDate>Fri, 27 Aug 2010 08:41:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>梦幻的php分页类~</title>
		<link>http://bluehua.org/2010/08/27/1434.html</link>
		<comments>http://bluehua.org/2010/08/27/1434.html#comments</comments>
		<pubDate>Fri, 27 Aug 2010 08:41:16 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[bookmark]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[pager]]></category>

		<guid isPermaLink="false">http://bluehua.org/2010/08/27/1434.html</guid>
		<description><![CDATA[以后发代码都会放到bookmark里，feed里不会看到了。
这次写了一个比较梦幻的分页类，简单，但是很好用。。
主要特点:

支持模板
支持sql和数组两种数据源

不适合:
没有对大量数据的分页做优化，所以不适用于变态分页.
简单举个例子,下面是一个对数组分页的例子

$pager = new Pager; 
$pager-&#62;count = count&#40;$data&#91;'contacts'&#93;&#41;;
$pager-&#62;count_per_page = 20;
$pager-&#62;param = 'p';
$pager-&#62;template = &#60;&#60;&#60;EOF
{start}-{end},共{count}&#60;br /&#62;
{first}&#60;a href=&#34;{first_url}&#34;&#62;首页&#60;/a&#62;&#124;{/first}
{pre}&#60;a href=&#34;{pre_url}&#34;&#62;上一页&#60;/a&#62;&#124;{/pre}
{next}&#60;a href=&#34;{next_url}&#34;&#62;下一页&#60;/a&#62;&#124;{/next}
{last}&#60;a href=&#34;{last_url}&#34;&#62;末页&#60;/a&#62;{/last}
EOF;
//对数组进行分页
foreach&#40;$pager-&#62;slice&#40;$data&#91;'contacts'&#93;&#41; as $contact&#41;:
//...

功能比较全的测试代码

$pager = new Pager; 
$pager-&#62;count = 200; 
$pager-&#62;count_per_page = 20;
$pager-&#62;param = 'p';
$pager-&#62;template = &#60;&#60;&#60;EOF
{first}&#60;a href=&#34;{first_url}&#34;&#62;首页&#60;/a&#62;{/first}
{pre}&#60;a href=&#34;{pre_url}&#34;&#62;上一页&#60;/a&#62;{/pre}
&#60;ul&#62;
{pages4}&#60;li&#62;&#60;a {current}style=&#34;color:red;&#34;{/current} href=&#34;{page_url}&#34;&#62;{page_num}&#60;/a&#62;&#60;/li&#62;{/pages4}
&#60;/ul&#62;
{next}&#60;a href=&#34;{next_url}&#34;&#62;下一页&#60;/a&#62;{/next}
{last}&#60;a href=&#34;{last_url}&#34;&#62;末页&#60;/a&#62;{/last}
{start}-{end}/{count}
&#60;select onchange=&#34;window.location.href=this.value;&#34;&#62;
{pages}&#60;option {current}selected=selected{/current} value=&#34;{page_url}&#34;&#62;{page_num}&#60;/a&#62;{/pages}
&#60;/select&#62;
EOF;
//这里使用sql获取数据
echo $p-&#62;get_sql&#40;'select * from xxx where xxx {limit}'&#41;;

代码:http://code-of-emptyhua.googlecode.com/svn/trunk/phplib/pager.class.php
&#8212;&#8212;&#8212;&#8211;
post by gmail~
]]></description>
			<content:encoded><![CDATA[<p>以后发代码都会放到bookmark里，feed里不会看到了。<br />
这次写了一个比较梦幻的分页类，简单，但是很好用。。</p>
<p>主要特点:</p>
<ul>
<li>支持模板</li>
<li>支持sql和数组两种数据源</li>
</ul>
<p>不适合:<br />
没有对大量数据的分页做优化，所以不适用于变态分页.</p>
<p>简单举个例子,下面是一个对数组分页的例子</p>

<div class="wp_syntax"><div class="code overflow"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$pager</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Pager<span style="color: #339933;">;</span> 
<span style="color: #000088;">$pager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'contacts'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count_per_page</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">param</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'p'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span> <span style="color: #339933;">=</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;EOF
{start}-{end},共{count}&lt;br /&gt;
{first}&lt;a href=&quot;{first_url}&quot;&gt;首页&lt;/a&gt;|{/first}
{pre}&lt;a href=&quot;{pre_url}&quot;&gt;上一页&lt;/a&gt;|{/pre}
{next}&lt;a href=&quot;{next_url}&quot;&gt;下一页&lt;/a&gt;|{/next}
{last}&lt;a href=&quot;{last_url}&quot;&gt;末页&lt;/a&gt;{/last}
EOF</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//对数组进行分页</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'contacts'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$contact</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
<span style="color: #666666; font-style: italic;">//...</span></pre></div></div>

<p>功能比较全的测试代码</p>

<div class="wp_syntax"><div class="code overflow"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$pager</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Pager<span style="color: #339933;">;</span> 
<span style="color: #000088;">$pager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$pager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count_per_page</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">param</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'p'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span> <span style="color: #339933;">=</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;EOF
{first}&lt;a href=&quot;{first_url}&quot;&gt;首页&lt;/a&gt;{/first}
{pre}&lt;a href=&quot;{pre_url}&quot;&gt;上一页&lt;/a&gt;{/pre}
&lt;ul&gt;
{pages4}&lt;li&gt;&lt;a {current}style=&quot;color:red;&quot;{/current} href=&quot;{page_url}&quot;&gt;{page_num}&lt;/a&gt;&lt;/li&gt;{/pages4}
&lt;/ul&gt;
{next}&lt;a href=&quot;{next_url}&quot;&gt;下一页&lt;/a&gt;{/next}
{last}&lt;a href=&quot;{last_url}&quot;&gt;末页&lt;/a&gt;{/last}
{start}-{end}/{count}
&lt;select onchange=&quot;window.location.href=this.value;&quot;&gt;
{pages}&lt;option {current}selected=selected{/current} value=&quot;{page_url}&quot;&gt;{page_num}&lt;/a&gt;{/pages}
&lt;/select&gt;
EOF</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//这里使用sql获取数据</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_sql</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'select * from xxx where xxx {limit}'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>代码:<a href="http://code-of-emptyhua.googlecode.com/svn/trunk/phplib/pager.class.php">http://code-of-emptyhua.googlecode.com/svn/trunk/phplib/pager.class.php</a></p>
<p>&#8212;&#8212;&#8212;&#8211;<br />
post by gmail~</p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/08/27/1434.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>日历的重复事件预测</title>
		<link>http://bluehua.org/2010/08/11/1417.html</link>
		<comments>http://bluehua.org/2010/08/11/1417.html#comments</comments>
		<pubDate>Wed, 11 Aug 2010 15:12:06 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[calendar]]></category>
		<category><![CDATA[repeat event]]></category>

		<guid isPermaLink="false">http://bluehua.org/2010/08/11/1417.html</guid>
		<description><![CDATA[本周开发一个web行事历，遇到一个比较繁琐的问题，就是重复事件。比如我创建了一个每周1,3,5重复的事件，当点击2012年的某月的日历时，需要显示这个事件会在哪几天发生。我又偷懒的去google找PHP源码，这回真的没有&#8230;,于是按照正常的想法实现了一个,不知道有没有更好的实现~
简述如下:
恩，问题描述出来就是找出特定规则的重复事件E在日期DA和日期DB之间会发生的日期，那么俺先粗略的在日期DA之前找一个事件E会发生日期DC然后从DC开始严格按照重复规则遍历,找出所有事件发生日期。
源代码:
http://code-of-emptyhua.googlecode.com/svn/trunk/phplib/calutil.class.php
&#8212;&#8212;&#8212;&#8211;
post by gmail~
]]></description>
			<content:encoded><![CDATA[<p>本周开发一个web行事历，遇到一个比较繁琐的问题，就是重复事件。比如我创建了一个每周1,3,5重复的事件，当点击2012年的某月的日历时，需要显示这个事件会在哪几天发生。我又偷懒的去google找PHP源码，这回真的没有&#8230;,于是按照正常的想法实现了一个,不知道有没有更好的实现~<br />
简述如下:<br />
恩，问题描述出来就是找出特定规则的重复事件E在日期DA和日期DB之间会发生的日期，那么俺先粗略的在日期DA之前找一个事件E会发生日期DC然后从DC开始严格按照重复规则遍历,找出所有事件发生日期。</p>
<p>源代码:<br />
<a href="http://code-of-emptyhua.googlecode.com/svn/trunk/phplib/calutil.class.php">http://code-of-emptyhua.googlecode.com/svn/trunk/phplib/calutil.class.php</a></p>
<p>&#8212;&#8212;&#8212;&#8211;<br />
post by gmail~</p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/08/11/1417.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>vim里快速调试PHP</title>
		<link>http://bluehua.org/2010/07/28/1407.html</link>
		<comments>http://bluehua.org/2010/07/28/1407.html#comments</comments>
		<pubDate>Wed, 28 Jul 2010 13:10:18 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://bluehua.org/2010/07/28/1407.html</guid>
		<description><![CDATA[恩，python中一般会把调试代码跟普通代码混在一块

class xx:
#    .....
if __name__ == '__main__':
    testxx = xx&#40;&#41;
    #测试代码....

这个__name__ == &#8216;__main__&#8217;判断此文件是否被直接执行，而不是被其他文件import,所以在vim中调试时可以直接输入:!python % 执行当前正在编辑的文件,调试代码便会执行并输出结果
php也可以这么加调试代码,php中是这么实现的

class xx &#123;
// ......
&#125;
//确定当前被执行的文件就是自己,而不是被其他php文件包含
if &#40;realpath&#40;$_SERVER&#91;'SCRIPT_FILENAME'&#93;&#41; == __FILE__&#41;
&#123;
    $testxx = new xx;
    //测试代码....
&#125;

如果仅限在命令行运行测试代码就再加个条件

if &#40;php_sapi_name&#40;&#41; == 'cli' &#38;&#38; realpath&#40;$_SERVER&#91;'SCRIPT_FILENAME'&#93;&#41; == __FILE__&#41;

为了更速度，vim配置里添加了一个快捷键F5

&#34;php和python调试快捷键
au FileType php map &#60;F5&#62; :call DebugRun&#40;'php'&#41;&#60;cr&#62;
au FileType php [...]]]></description>
			<content:encoded><![CDATA[<p>恩，python中一般会把调试代码跟普通代码混在一块</p>

<div class="wp_syntax"><div class="code overflow"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> xx:
<span style="color: #808080; font-style: italic;">#    .....</span>
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    testxx = xx<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #808080; font-style: italic;">#测试代码....</span></pre></div></div>

<p>这个__name__ == &#8216;__main__&#8217;判断此文件是否被直接执行，而不是被其他文件import,所以在vim中调试时可以直接输入:!python % 执行当前正在编辑的文件,调试代码便会执行并输出结果</p>
<p>php也可以这么加调试代码,php中是这么实现的</p>

<div class="wp_syntax"><div class="code overflow"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> xx <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// ......</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//确定当前被执行的文件就是自己,而不是被其他php文件包含</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_FILENAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$testxx</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xx<span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//测试代码....</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>如果仅限在命令行运行测试代码就再加个条件</p>

<div class="wp_syntax"><div class="code overflow"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">php_sapi_name</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'cli'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_FILENAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>为了更速度，vim配置里添加了一个快捷键F5</p>

<div class="wp_syntax"><div class="code overflow"><pre class="vim" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">&quot;php和python调试快捷键</span>
au FileType php <span style="color: #25BB4D;">map</span> <span style="color: #000000;">&lt;</span>F5<span style="color: #000000;">&gt;</span> <span style="color: #000000;">:</span><span style="color: #804040;">call</span> DebugRun<span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'php'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&lt;</span>cr<span style="color: #000000;">&gt;</span>
au FileType php imap <span style="color: #000000;">&lt;</span>F5<span style="color: #000000;">&gt;</span> <span style="color: #000000;">&lt;</span>Esc<span style="color: #000000;">&gt;:</span><span style="color: #804040;">call</span> DebugRun<span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'php'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&lt;</span>cr<span style="color: #000000;">&gt;</span>
au FileType python <span style="color: #25BB4D;">map</span> <span style="color: #000000;">&lt;</span>F5<span style="color: #000000;">&gt;</span> <span style="color: #000000;">:</span><span style="color: #804040;">call</span> DebugRun<span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'python'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&lt;</span>cr<span style="color: #000000;">&gt;</span>
au FileType python imap <span style="color: #000000;">&lt;</span>F5<span style="color: #000000;">&gt;</span> <span style="color: #000000;">&lt;</span>Esc<span style="color: #000000;">&gt;:</span><span style="color: #804040;">call</span> DebugRun<span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'python'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&lt;</span>cr<span style="color: #000000;">&gt;</span>
<span style="color: #804040;">function</span> DebugRun<span style="color: #000000;">&#40;</span>cmd<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">:</span>w
    <span style="color: #804040;">execute</span> <span style="color: #C5A22D;">'!'</span> <span style="color: #000000;">.</span> a<span style="color: #000000;">:</span>cmd <span style="color: #000000;">.</span> <span style="color: #C5A22D;">' %'</span>
endfunction</pre></div></div>

<p>OK,写完调试代码按下F5立刻有结果。</p>
<p>&#8212;&#8212;&#8212;&#8211;<br />
post by gmail~</p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/07/28/1407.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>last_insert_id脑残?</title>
		<link>http://bluehua.org/2010/07/21/1391.html</link>
		<comments>http://bluehua.org/2010/07/21/1391.html#comments</comments>
		<pubDate>Wed, 21 Jul 2010 10:39:52 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[last_insert_id]]></category>
		<category><![CDATA[mysql_insert_id]]></category>

		<guid isPermaLink="false">http://bluehua.org/2010/07/21/1391.html</guid>
		<description><![CDATA[
//前面插入操作省略...
$rt = mysql_insert_id&#40;&#41;;
var_dump&#40;$rt&#41;;
$rt = $this-&#62;DB-&#62;query&#40;&#34;select last_insert_id() from yl_contact&#34;&#41;;
var_dump&#40;$rt&#41;;
//结果
//
//int(10000672)
//int(15476)

10000672这个结果是准确的，15476是索引总量，也就是说这个表里的自增字段有一段是空的，但是有影响吗？
为什么mysql_insert_id()这个函数这么靠普呢? 因为它直接返回了上次插入返回结果里的insert_id

my_ulonglong STDCALL mysql_insert_id&#40;MYSQL *mysql&#41;
&#123;
    return mysql-&#62;last_used_con-&#62;insert_id;
&#125;

还是没弄明白为什么，求解~
&#8212;&#8212;&#8212;&#8211;
post by gmail~
]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code overflow"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//前面插入操作省略...</span>
<span style="color: #000088;">$rt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_insert_id</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select last_insert_id() from yl_contact&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//结果</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">//int(10000672)</span>
<span style="color: #666666; font-style: italic;">//int(15476)</span></pre></div></div>

<p>10000672这个结果是准确的，15476是索引总量，也就是说这个表里的自增字段有一段是空的，但是有影响吗？</p>
<p>为什么mysql_insert_id()这个函数这么靠普呢? 因为它直接返回了上次插入返回结果里的insert_id</p>

<div class="wp_syntax"><div class="code overflow"><pre class="c" style="font-family:monospace;">my_ulonglong STDCALL mysql_insert_id<span style="color: #009900;">&#40;</span>MYSQL <span style="color: #339933;">*</span>mysql<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> mysql<span style="color: #339933;">-&gt;</span>last_used_con<span style="color: #339933;">-&gt;</span>insert_id<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>还是没弄明白为什么，求解~</p>
<p>&#8212;&#8212;&#8212;&#8211;<br />
post by gmail~</p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/07/21/1391.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>php2wsdl</title>
		<link>http://bluehua.org/2010/07/13/1336.html</link>
		<comments>http://bluehua.org/2010/07/13/1336.html#comments</comments>
		<pubDate>Tue, 13 Jul 2010 07:16:46 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[webservice]]></category>
		<category><![CDATA[wsdl]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1336</guid>
		<description><![CDATA[搞webservice最痛苦的莫过于提供wsdl，前两天找到一个叫&#8221;PHP WSDL Generator&#8221;的工具，可以根据注释生成wsdl，刚开始写了一个测试类还行，后来发现问题多多，文件里有require一类引用外部文件时会出问题，写同样的注释有的函数可以正确的生成，有的函数却不行。这种深不可测的东西不用也罢，自己写了一个。虽然功能弱点，但是不会无厘头。
下载:http://code-of-emptyhua.googlecode.com/svn/trunk/php2wsdl.py
命令行的话这样：

#参数依次为 命名空间 提供服务的PHP的类名 soap访问地址 本地的PHP文件 生成wsd的保存地址
php2wsdl.py &#34;Ox-Service&#34; &#34;SomeClass&#34; &#34;http://test.com/soapserver.php&#34; ./SomeClass.php ./service.wsdl

图简单，这个脚本生成的wsdl会把array类型当成anyType,实际用的时候没有什么问题～
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
另:
打包上传比较麻烦，以后就用google code传东西了，也比较好管理
跟上面一块传的还有一段汉字转拼音的python脚本:http://code-of-emptyhua.googlecode.com/svn/trunk/hz2py，写这个脚本因为最近想注个好点的com域名，但是差来查去都被注册，难道好记点的域名真的光了吗。。于是从一个分词字典里生成了一个快5万个域名的txt，跑了一个whois脚本，最后结果没有注册只有不到300个，而且基本都是多音字。。只能叹生不逢时~
]]></description>
			<content:encoded><![CDATA[<p>搞webservice最痛苦的莫过于提供wsdl，前两天找到一个叫&#8221;PHP WSDL Generator&#8221;的工具，可以根据注释生成wsdl，刚开始写了一个测试类还行，后来发现问题多多，文件里有require一类引用外部文件时会出问题，写同样的注释有的函数可以正确的生成，有的函数却不行。这种深不可测的东西不用也罢，自己写了一个。虽然功能弱点，但是不会无厘头。</p>
<p>下载:<a href="http://code-of-emptyhua.googlecode.com/svn/trunk/php2wsdl.py">http://code-of-emptyhua.googlecode.com/svn/trunk/php2wsdl.py</a></p>
<p>命令行的话这样：</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#参数依次为 命名空间 提供服务的PHP的类名 soap访问地址 本地的PHP文件 生成wsd的保存地址</span>
php2wsdl.py <span style="color: #ff0000;">&quot;Ox-Service&quot;</span> <span style="color: #ff0000;">&quot;SomeClass&quot;</span> <span style="color: #ff0000;">&quot;http://test.com/soapserver.php&quot;</span> .<span style="color: #000000; font-weight: bold;">/</span>SomeClass.php .<span style="color: #000000; font-weight: bold;">/</span>service.wsdl</pre></div></div>

<p>图简单，这个脚本生成的wsdl会把array类型当成anyType,实际用的时候没有什么问题～</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
另:<br />
打包上传比较麻烦，以后就用google code传东西了，也比较好管理<br />
跟上面一块传的还有一段汉字转拼音的python脚本:<a href="http://code-of-emptyhua.googlecode.com/svn/trunk/hz2py">http://code-of-emptyhua.googlecode.com/svn/trunk/hz2py</a>，写这个脚本因为最近想注个好点的com域名，但是差来查去都被注册，难道好记点的域名真的光了吗。。于是从一个分词字典里生成了一个快5万个域名的txt，跑了一个whois脚本，最后结果没有注册只有不到300个，而且基本都是多音字。。只能叹生不逢时~</p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/07/13/1336.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php的一个表单验证类</title>
		<link>http://bluehua.org/2010/04/23/1150.html</link>
		<comments>http://bluehua.org/2010/04/23/1150.html#comments</comments>
		<pubDate>Fri, 23 Apr 2010 15:19:36 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[web dev]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[validate]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1150</guid>
		<description><![CDATA[做web这么长时间,感觉最恶心的就是表单验证这块了,很无聊,很烦琐,也很重要..
这个验证类的功能参考了codeigniter的表单验证库的功能,按照我的想法实现完毕又去对照codeigniter的代码,感觉还是我的这个比较灵活实用&#8230;

/**
 * 表单验证类
 * Author : emptyhua@gmail.com
 * Version : beta
 */
&#160;
class FormValidator
&#123;
    //所有验证函数定义时的前缀
    const PREFIX = 'form_validator_';
&#160;
    //存储验证函数的出错信息
    public static $error_messages = array&#40;&#41;;
&#160;
    //存储验证相关的数据
    protected $valid_rules = array&#40;&#41;; 
&#160;
    //存储上次验证的出错信息
    [...]]]></description>
			<content:encoded><![CDATA[<p>做web这么长时间,感觉最恶心的就是表单验证这块了,很无聊,很烦琐,也很重要..<br />
这个验证类的功能参考了<a href="http://codeigniter.org.cn/user_guide/libraries/form_validation.html">codeigniter的表单验证库</a>的功能,按照我的想法实现完毕又去对照codeigniter的代码,感觉还是我的这个比较灵活实用<img class="xemotion" src="http://bluehua.org/wp-content/plugins/x-emotions/emotions/msn/bofu1_12.gif" border="0" alt="" />&#8230;</p>

<div class="wp_syntax"><div class="code overflow"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * 表单验证类
 * Author : emptyhua@gmail.com
 * Version : beta
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> FormValidator
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//所有验证函数定义时的前缀</span>
    <span style="color: #000000; font-weight: bold;">const</span> PREFIX <span style="color: #339933;">=</span> <span style="color: #0000ff;">'form_validator_'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//存储验证函数的出错信息</span>
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000088;">$error_messages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//存储验证相关的数据</span>
    protected <span style="color: #000088;">$valid_rules</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
    <span style="color: #666666; font-style: italic;">//存储上次验证的出错信息</span>
    protected <span style="color: #000088;">$errors</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//是否完全检查</span>
    protected <span style="color: #000088;">$complete_check</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> set_error<span style="color: #009900;">&#40;</span><span style="color: #000088;">$rule</span><span style="color: #339933;">,</span> <span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$error_messages</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$rule</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$error</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * 遇到第一个错误便返回
     */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> first_error_only<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">complete_check</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * 执行所有验证规则,收集所有错误
     */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> show_all_errors<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">complete_check</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * 设置验证规则
     * @param string $var 验证的变量名,例如 username
     * @param string $var_name 变量名的描述,例如 用户名
     * @param string $func_name 验证规则,可以是多个,并且可以传参,例如 require|length(9,12)
     * @param string $error_message 自定义的出错信息,可选,如果给定将覆盖验证函数的默认出错信息
     */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> set_rules<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$func_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$error_message</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'var_name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$var_name</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$error_message</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'funcs'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$funcs_with_arg</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'|'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$func_name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$args_match</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//解析验证规则</span>
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$funcs_with_arg</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$func_with_arg</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/\((.*)\)$/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$func_with_arg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args_match</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #666666; font-style: italic;">//规则函数是否携带参数</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args_match</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">//参数列表</span>
                <span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args_match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #666666; font-style: italic;">//去掉参数后的验证规则名</span>
                <span style="color: #000088;">$func</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'('</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$args_match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">')'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$func_with_arg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'funcs'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$func</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">else</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'funcs'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$func_with_arg</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">valid_rules</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * 检验一组数据是否合法
     * @param array $data 一个关联数组
     * @return boolean
     */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> is_valid<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errors</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$valid</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//遍历的顺序为规则添加的顺序</span>
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">valid_rules</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$var</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$rule</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//判断数据中是否有此字段,没有的话置一个空的</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
                <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rule</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'funcs'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$func</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">//真实的验证函数的名称,例如 form_validator_require</span>
                <span style="color: #000088;">$func_run</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">PREFIX</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$func</span><span style="color: #339933;">;</span>
                <span style="color: #666666; font-style: italic;">//如果函数未定义,循环继续</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_callable</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$func_run</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">//为验证函数组装参数</span>
                <span style="color: #666666; font-style: italic;">//顺序为:当前验证字段的值, 所有验证数据, 验证规则参数1, ...</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$args</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">NULL</span> <span style="color: #009900;">&#41;</span> 
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">else</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #990000;">array_unshift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #990000;">array_unshift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">//调用验证函数</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">call_user_func_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$func_run</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$valid</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                    <span style="color: #666666; font-style: italic;">//如果set_rules的时候没有自定义错误信息,则使用默认出错信息</span>
                    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$rule</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">NULL</span> <span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                        <span style="color: #666666; font-style: italic;">//使用sprintf拼接错误信息</span>
                        <span style="color: #666666; font-style: italic;">//参数顺序: 验证字段的描述, 验证函数的参数1, 验证函数的参数2 ...</span>
&nbsp;
                        <span style="color: #666666; font-style: italic;">//去掉刚才添加的字段值</span>
                        <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #666666; font-style: italic;">//去掉刚才添加的所有验证数据</span>
                        <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #666666; font-style: italic;">//添加字段名的描述</span>
                        <span style="color: #990000;">array_unshift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000088;">$rule</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'var_name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #666666; font-style: italic;">//添加默认的出错信息</span>
                        <span style="color: #990000;">array_unshift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$error_messages</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$func</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errors</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">call_user_func_array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sprintf'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #b1b100;">else</span>
                    <span style="color: #009900;">&#123;</span>
                        <span style="color: #666666; font-style: italic;">//使用自定义错误信息</span>
                        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errors</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rule</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">continue</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
&nbsp;
                    <span style="color: #666666; font-style: italic;">//如果设置不进行完全检查,则发现第一个错误后跳出最外层循环</span>
                    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">complete_check</span> <span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                        <span style="color: #b1b100;">break</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span> 
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$valid</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * 获取出错信息
     * @return string array
     */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> get_errors<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errors</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * 返回第一条出错信息
     * @return string
     */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> get_first_error<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errors</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//扩展验证规则很方便~</span>
<span style="color: #666666; font-style: italic;">//设置规则的默认出错信息</span>
FormValidator<span style="color: #339933;">::</span><span style="color: #004000;">set_error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'require'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'%s不能为空'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//定义验证函数,以FormValidator::PREFIX打头</span>
<span style="color: #000000; font-weight: bold;">function</span> form_validator_require<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
FormValidator<span style="color: #339933;">::</span><span style="color: #004000;">set_error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'equal'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'重复输入不一致'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> form_validator_equal<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$eqto</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$eqto</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$eqto</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>使用方法</p>

<div class="wp_syntax"><div class="code overflow"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$vd</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FormValidator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$vd</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'密码'</span><span style="color: #339933;">,</span>  <span style="color: #0000ff;">'require|length(9,12)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$vd</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p2'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'密码验证'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'equa(p)'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'两次密码输入不一致'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$vd</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">is_valid</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$vd</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_errors</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/04/23/1150.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php整型溢出导致的小问题~</title>
		<link>http://bluehua.org/2010/03/29/1046.html</link>
		<comments>http://bluehua.org/2010/03/29/1046.html#comments</comments>
		<pubDate>Mon, 29 Mar 2010 15:58:20 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[debug]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1046</guid>
		<description><![CDATA[今天把一直本地测试的php程序放到外网的机器跑(64位系统),没想到一个纯算数值的算法竟然得到不一样的结果,最后锁定在一个求模的操作上:$i % 4, $i在本地和server上打印出来都是434807526976, 但是求出来的结果却不一样~
原因是:
php的整型最大值为2147483647(32位系统上), 当数值赋值超过这个最大值时,变量便自动成为浮点型. 所以虽然打印出来一样,但本地打印的是一个是浮点型的$i,而server上是64位系统,整型最大值达到9223372036854775807  &#8230;. $i依然是一个整型.
取模运算的结果不一样是因为php在对数值取模运算时会把浮点数转换为整型再取模(这点就不如js了,js是可以对浮点取模运算地~)
所以本地32位系统运行的其实是: ((int) $i) % 4 即 512559680 % 4
解决方法 : 最后为了保持与其他平台的一致,强制在64系统也&#8221;溢出&#8221; : ($i &#38; 0xFFFFFFFF) % 4
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
php也是一个比较无厘头的东西~
]]></description>
			<content:encoded><![CDATA[<p>今天把一直本地测试的php程序放到外网的机器跑(64位系统),没想到一个纯算数值的算法竟然得到不一样的结果,最后锁定在一个求模的操作上:$i % 4, $i在本地和server上打印出来都是434807526976, 但是求出来的结果却不一样~</p>
<p>原因是:<br />
php的整型最大值为2147483647(32位系统上), <strong>当数值赋值超过这个最大值时,变量便自动成为浮点型</strong>. 所以虽然打印出来一样,但本地打印的是一个是浮点型的$i,而server上是64位系统,整型最大值达到9223372036854775807  &#8230;. $i依然是一个整型.</p>
<p>取模运算的结果不一样是因为<strong>php在对数值取模运算时会把浮点数转换为整型再取模</strong>(这点就不如js了,js是可以对浮点取模运算地~)</p>
<p>所以本地32位系统运行的其实是: ((int) $i) % 4 即 512559680 % 4</p>
<p>解决方法 : 最后为了保持与其他平台的一致,强制在64系统也&#8221;溢出&#8221; : ($i &amp; 0xFFFFFFFF) % 4</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>php也是一个比较无厘头的东西~</p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/03/29/1046.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php实现AES/ECB/PKCS5Padding加密</title>
		<link>http://bluehua.org/2010/03/20/1039.html</link>
		<comments>http://bluehua.org/2010/03/20/1039.html#comments</comments>
		<pubDate>Sat, 20 Mar 2010 10:35:02 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[bookmark]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[aes]]></category>
		<category><![CDATA[ecb]]></category>
		<category><![CDATA[pkcs5]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1039</guid>
		<description><![CDATA[基于一哥们代码的修改版:http://www.codigg.com/2010/01/php-aes-java-encrypt-decrypt/

class CryptAES
&#123;
    protected $cipher     = MCRYPT_RIJNDAEL_128;
    protected $mode       = MCRYPT_MODE_ECB;
    protected $pad_method = NULL;
    protected $secret_key = '';
    protected $iv         = '';
&#160;
&#160;
 [...]]]></description>
			<content:encoded><![CDATA[<p>基于一哥们代码的修改版:<a href="http://www.codigg.com/2010/01/php-aes-java-encrypt-decrypt/">http://www.codigg.com/2010/01/php-aes-java-encrypt-decrypt/</a></p>

<div class="wp_syntax"><div class="code overflow"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> CryptAES
<span style="color: #009900;">&#123;</span>
    protected <span style="color: #000088;">$cipher</span>     <span style="color: #339933;">=</span> MCRYPT_RIJNDAEL_128<span style="color: #339933;">;</span>
    protected <span style="color: #000088;">$mode</span>       <span style="color: #339933;">=</span> MCRYPT_MODE_ECB<span style="color: #339933;">;</span>
    protected <span style="color: #000088;">$pad_method</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
    protected <span style="color: #000088;">$secret_key</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
    protected <span style="color: #000088;">$iv</span>         <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> set_cipher<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cipher</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cipher</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cipher</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> set_mode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$mode</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mode</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mode</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> set_iv<span style="color: #009900;">&#40;</span><span style="color: #000088;">$iv</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">iv</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$iv</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> set_key<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">secret_key</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$key</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> require_pkcs5<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pad_method</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'pkcs5'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    protected <span style="color: #000000; font-weight: bold;">function</span> pad_or_unpad<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ext</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pad_method</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> 
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$func_name</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">__CLASS__</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'::'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pad_method</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ext</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'pad'</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">is_callable</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$func_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mcrypt_get_block_size</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cipher</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mode</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #990000;">call_user_func</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$func_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>
&nbsp;
    protected <span style="color: #000000; font-weight: bold;">function</span> pad<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pad_or_unpad</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>
&nbsp;
    protected <span style="color: #000000; font-weight: bold;">function</span> unpad<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pad_or_unpad</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'un'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> encrypt<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pad</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$td</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mcrypt_module_open</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cipher</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mode</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">iv</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$iv</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mcrypt_create_iv</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mcrypt_enc_get_iv_size</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$td</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> MCRYPT_RAND<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$iv</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">iv</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #990000;">mcrypt_generic_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$td</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">secret_key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$iv</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$cyper_text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mcrypt_generic</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$td</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$rt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">bin2hex</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cyper_text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">mcrypt_generic_deinit</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$td</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">mcrypt_module_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$td</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$rt</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> decrypt<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$td</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mcrypt_module_open</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cipher</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mode</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">iv</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$iv</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mcrypt_create_iv</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mcrypt_enc_get_iv_size</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$td</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> MCRYPT_RAND<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$iv</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">iv</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #990000;">mcrypt_generic_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$td</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">secret_key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$iv</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$decrypted_text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mdecrypt_generic</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$td</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">hex2bin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$rt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$decrypted_text</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">mcrypt_generic_deinit</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$td</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">mcrypt_module_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$td</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">unpad</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> hex2bin<span style="color: #009900;">&#40;</span><span style="color: #000088;">$hexdata</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$bindata</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$length</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hexdata</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$length</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$bindata</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">hexdec</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hexdata</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$bindata</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> pkcs5_pad<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$blocksize</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$pad</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$blocksize</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #000088;">$blocksize</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span> <span style="color: #339933;">.</span> <span style="color: #990000;">str_repeat</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pad</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pad</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> pkcs5_unpad<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$pad</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#123;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pad</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strspn</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pad</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$pad</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$pad</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$pad</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>主要改进就是支持pkcs5补齐了,使用方法如下~</p>

<div class="wp_syntax"><div class="code overflow"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$aes</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CryptAES<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$aes</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_key</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1234567890123456'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$aes</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">require_pkcs5</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$aes</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">encrypt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'abcd'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$rt</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;br/&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$aes</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">decrypt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rt</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;br/&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/03/20/1039.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>一个php应用最开始一般会做的事</title>
		<link>http://bluehua.org/2010/03/13/1013.html</link>
		<comments>http://bluehua.org/2010/03/13/1013.html#comments</comments>
		<pubDate>Sat, 13 Mar 2010 14:53:53 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1013</guid>
		<description><![CDATA[OK,php回顾之旅开始~

检查PHP版本,一般发行版软件会这么做

//wordpress
if ( version_compare( '4.3', phpversion(), '>' ) ) {
//MediaWiki
# Check for PHP 5
if ( !function_exists( 'version_compare' )
	&#124;&#124; version_compare( phpversion(), '5.0.0' ) < 0


检查对性能或者安全有影响的配置项

//wordpress 尝试设置内存限制
@ini_set('memory_limit', WP_MEMORY_LIMIT);


//MediaWiki
if ( ini_get( 'register_globals' ) ) {
//....如果自动全局变量下面将检查是否存在有害的参数

@ini_set( 'allow_url_fopen', 0 ); # For security


定义有用的常量

//wordpress
//定义根目录
define( 'ABSPATH', dirname(__FILE__) . '/' );
//定义语言, 有时会也会根据用户的语言设置初始化
define ('WPLANG', 'zh_CN');


针对不同平台,不同httpd软件的兼容代码,一般发行版软件会做

//wordpress,针对iis的兼容代码
// IIS Mod-Rewrite
	if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
		$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
	}


初始化用于debug或者profile的函数,强大与否并不重要,但是没有是灰常不专业的...

//wordpress
if ( defined('WP_DEBUG') &#038;&#038; WP_DEBUG [...]]]></description>
			<content:encoded><![CDATA[<p>OK,php回顾之旅开始~</p>
<ul>
<li>检查PHP版本,一般发行版软件会这么做
<pre>
//wordpress
if ( version_compare( '4.3', phpversion(), '>' ) ) {
//MediaWiki
# Check for PHP 5
if ( !function_exists( 'version_compare' )
	|| version_compare( phpversion(), '5.0.0' ) < 0
</pre>
</li>
<li>检查对性能或者安全有影响的配置项<br/>
<pre>
//wordpress 尝试设置内存限制
@ini_set('memory_limit', WP_MEMORY_LIMIT);
</pre>
<pre>
//MediaWiki
if ( ini_get( 'register_globals' ) ) {
//....如果自动全局变量下面将检查是否存在有害的参数

@ini_set( 'allow_url_fopen', 0 ); # For security
</pre>
</li>
<li>定义有用的常量<br/>
<pre>
//wordpress
//定义根目录
define( 'ABSPATH', dirname(__FILE__) . '/' );
//定义语言, 有时会也会根据用户的语言设置初始化
define ('WPLANG', 'zh_CN');
</pre>
</li>
<li>针对不同平台,不同httpd软件的兼容代码,一般发行版软件会做
<pre>
//wordpress,针对iis的兼容代码
// IIS Mod-Rewrite
	if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
		$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
	}
</pre>
</li>
<li>初始化用于debug或者profile的函数,强大与否并不重要,但是没有是灰常不专业的...
<pre>
//wordpress
if ( defined('WP_DEBUG') &#038;&#038; WP_DEBUG ) {
....
</pre>
</li>
<li>加载通用的库文件或者框架
<pre>
require (ABSPATH . WPINC . '/functions.php');
</pre>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/03/13/1013.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wordpress plugin:搜索引擎关键词高亮</title>
		<link>http://bluehua.org/2009/07/22/333.html</link>
		<comments>http://bluehua.org/2009/07/22/333.html#comments</comments>
		<pubDate>Wed, 22 Jul 2009 15:14:30 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[highlight]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=333</guid>
		<description><![CDATA[下载地址更新 2009.11.8
http://wordpress.org/extend/plugins/keywords-highlight-tool/
&#8212;&#8212;&#8212;-
由于blog的访客多来自搜索引擎,所以关键词高亮会大大的增强访客的浏览体验,帮助访客快速定位感兴趣的内容.
类似插件已有很多,但俺绝不是再造普通的轮子,一定要用浏览器兼容性最好的插件,没有就自己搞..
现存插件的实现方式有两种,一种用php在后端实现,另一种用js在前端实现.
php实现高亮,浏览器兼容性最好,但是有两个问题:
1.效率问题,不如用js实现,将压力分到前端; 2.不支持cache类插件,当然这个问题可以通过hack cache插件解决,但是不可取.
js实现高亮:
比较理想的实现方法,搜到一篇文章叫也谈Wordpress关键词高亮 里面讲到用js高亮关键词,但是中文gb转码使用了vbscript,所以仅支持ie浏览器
于是用自己的想法简单实现了一下这个功能, 点击搜索测试 第一个结果就应该是了
screenshot:

跟上面提到插件的主要不同点:

改进了高亮的实现方法,仅替换元素的text节点,防止造成元素事件失效
判断如果不是外链过来的访客将不加载高亮的js脚本
百度链接过来,中文gb转码时使用php后台转码,兼容所有主流浏览器

目前仅添加了对google,yahoo,baidu三个搜索引擎的支持,如果想支持更多,自行修改highlight.js即可
插件下载点这里
]]></description>
			<content:encoded><![CDATA[<p>下载地址更新 2009.11.8<br />
<a href="http://wordpress.org/extend/plugins/keywords-highlight-tool/">http://wordpress.org/extend/plugins/keywords-highlight-tool/</a><br />
&#8212;&#8212;&#8212;-<br />
由于blog的访客多来自搜索引擎,所以关键词高亮会大大的增强访客的浏览体验,帮助访客快速定位感兴趣的内容.</p>
<p>类似插件已有很多,但俺绝不是再造普通的轮子,一定要用浏览器兼容性最好的插件,没有就自己搞..</p>
<p>现存插件的实现方式有两种,一种用php在后端实现,另一种用js在前端实现.</p>
<p>php实现高亮,浏览器兼容性最好,但是有两个问题:</p>
<p>1.效率问题,不如用js实现,将压力分到前端; 2.不支持cache类插件,当然这个问题可以通过hack cache插件解决,但是不可取.</p>
<p>js实现高亮:</p>
<p>比较理想的实现方法,搜到一篇文章叫<a href="http://www.jefflei.com/post/1041.html" target="_blank">也谈Wordpress关键词高亮</a> 里面讲到用js高亮关键词,但是中文gb转码使用了vbscript,所以仅支持ie浏览器</p>
<p>于是用自己的想法简单实现了一下这个功能, <a href="http://www.google.cn/search?hl=zh-CN&amp;rlz=1B3GGGL_zh-CNCN330CN331&amp;newwindow=1&amp;q=ajax+document+write+%E6%9D%8E%E5%AE%81+%E5%86%85%E8%81%94%E8%84%9A%E6%9C%AC+%E8%84%9A%E6%9C%AC&amp;btnG=Google+%E6%90%9C%E7%B4%A2" target="_blank">点击搜索测试</a> 第一个结果就应该是了<img class="xemotion" src="http://bluehua.org/wp-content/plugins/x-emotions/emotions/char/icon_lol.gif" border="0" alt="" /></p>
<p>screenshot:</p>
<p><a href="http://bluehua.org/wp-content/uploads/2009/07/2009-7-21-21-48-56.png"><img class="alignnone size-full wp-image-336" title="2009-7-21-21-48-56" src="http://bluehua.org/wp-content/uploads/2009/07/2009-7-21-21-48-56.png" alt="2009-7-21-21-48-56" width="565" height="518" /></a></p>
<p>跟上面提到插件的主要不同点:</p>
<ul>
<li>改进了高亮的实现方法,仅替换元素的text节点,防止造成元素事件失效</li>
<li>判断如果不是外链过来的访客将不加载高亮的js脚本</li>
<li>百度链接过来,中文gb转码时使用php后台转码,兼容所有主流浏览器</li>
</ul>
<p>目前仅添加了对google,yahoo,baidu三个搜索引擎的支持,如果想支持更多,自行修改highlight.js即可</p>
<p><a href="http://sites.google.com/site/sharemyidea09/wordpress-keywords-highlight-tool" target="_blank">插件下载点这里</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2009/07/22/333.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 2.395 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-09-07 10:39:16 -->
