<?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://www.boluor.com/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.boluor.com</link>
	<description></description>
	<lastBuildDate>Fri, 07 Oct 2011 07:28:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>某一天是星期几 &amp;&amp; php的整除</title>
		<link>http://www.boluor.com/weekday-of-oneday-and-exact-division-in-php.html</link>
		<comments>http://www.boluor.com/weekday-of-oneday-and-exact-division-in-php.html#comments</comments>
		<pubDate>Mon, 17 May 2010 15:24:27 +0000</pubDate>
		<dc:creator>boluor</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[算法]]></category>

		<guid isPermaLink="false">http://www.boluor.com/?p=635</guid>
		<description><![CDATA[<p>最近在写日程管理系统，其中有个蛮有趣的问题，如何知道某一天是星期几？</p>
<p>假设日期是2010-5-17，php中用date函数可以轻松得得到。date函数的用法：<br />
string date ( string $format [, int $timestamp ] )<br />
$format为”w”时，可以获取timestamp对应的星期的数字编号，0代表Sunday,1代表Monday&#8230;6表示Saturday。date(“w”,mktime(1,1,1,5,17,2010))就可以获取2010-5-17所对应的星期了。</p>
<p>记得之前sandy推荐给我看的linux下mktime实现的源码分析中，提到了一个magic numbe&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>最近在写日程管理系统，其中有个蛮有趣的问题，如何知道某一天是星期几？</p>
<p>假设日期是2010-5-17，php中用date函数可以轻松得得到。date函数的用法：<br />
string date ( string $format [, int $timestamp ] )<br />
$format为”w”时，可以获取timestamp对应的星期的数字编号，0代表Sunday,1代表Monday&#8230;6表示Saturday。date(“w”,mktime(1,1,1,5,17,2010))就可以获取2010-5-17所对应的星期了。</p>
<p>记得之前sandy推荐给我看的linux下mktime实现的源码分析中，提到了一个magic number，还有神奇的Gauss算法。温习时发现了很多讨论某一天是星期几的算法。其中比较著名的有基姆拉尔森计算公式和蔡勒公式。</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;以下摘自百度百科&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
基姆拉尔森计算公式：<br />
W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7<br />
在公式中d表示日期中的日数，m表示月份数，y表示年数。在公式中有个与其他公式不同的地方：把一月和二月看成是上一年的十三月和十四月，例：如果是2004-1-10则换算成：2003-13-10来代入公式计算。结果中0表示Monday , 1 表示 Tuesday &#8230; 6表示Sunday，跟date函数的不同。</p>
<p>蔡勒公式如下：<br />
　　W = [C/4] &#8211; 2C + y + [y/4] + [13 * (M+1) / 5] + d &#8211; 1<br />
　　或者是:w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1<br />
　　公式中的符号含义如下：<br />
　　w：星期； w对7取模得：0-星期日，1-星期一，2-星期二，3-星期三，4-星期四，5-星期五，6-星期六<br />
　　c：世纪-1（前两位数）<br />
　　y：年（后两位数）<br />
　　m：月（m大于等于3，小于等于14，即在蔡勒公式中，某年的1、2月要看作上一年的13、14月来计算，比如2003年1月1日要看作2002年的13月1日来计算）<br />
　　d：日<br />
　　[ ]代表取整，即只要整数部分。</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;以上摘自百度百科&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>用php实现了下：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #000000; font-weight: bold;">function</span> day2week<span style="color: #009900;">&#40;</span><span style="color: #000088;">$year</span><span style="color: #339933;">,</span><span style="color: #000088;">$month</span><span style="color: #339933;">,</span><span style="color: #000088;">$day</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: #000088;">$month</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$year</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$year</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$month</span> <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">12</span> <span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">*</span><span style="color: #000088;">$month</span> <span style="color: #339933;">+</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$month</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">5</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$year</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$year</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">4</span> <span style="color: #339933;">-</span>
 <span style="color: #000088;">$year</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">100</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$year</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">400</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span>  <span style="color: #cc66cc;">7</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$w</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>但测试时发现结果不对头。跟sandy讨论了会儿，发现用C语言实现的程序运行结果是正确的，才想到是php的整除的问题，php的动态类型的机制，“/”之类的结果是浮点类型的。要想得到和C语言一样的整除的效果，就要配合floor和ceil两个取整函数了。C中取整都是向0靠拢，也就是说如果结果是负数，就取大于等于结果的最小整数；结果是正数，就取小于等于结果的最大整数。一个php中的类似实现：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #000000; font-weight: bold;">function</span> rst2int<span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span> <span style="color: #339933;">,</span><span style="color: #000088;">$b</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: #000088;">$b</span> <span style="color: #339933;">&lt;</span> <span style="color:#800080;">1e-9</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;error&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$rst</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$a</span><span style="color: #339933;">/</span><span style="color: #000088;">$b</span> <span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$rst</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> ? <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rst</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rst</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">echo</span> rst2int<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> rst2int<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> rst2int<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>写脚本的时候还是要特别注意才好啊~</p>
]]></content:encoded>
			<wfw:commentRss>http://www.boluor.com/weekday-of-oneday-and-exact-division-in-php.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>批量修改文章中的标签</title>
		<link>http://www.boluor.com/update-tags-of-posts-in-batch.html</link>
		<comments>http://www.boluor.com/update-tags-of-posts-in-batch.html#comments</comments>
		<pubDate>Sat, 22 Aug 2009 20:19:56 +0000</pubDate>
		<dc:creator>boluor</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[正则表达式]]></category>

		<guid isPermaLink="false">http://www.boluor.com/?p=299</guid>
		<description><![CDATA[<p>　　实在受不了syntax highlighter的速度，所以暂时去找了个wp-syntax高亮插件来代替。问题来了，我之前使用时标签都是类似：［c］［/c］，［php］［/php］的，当时偷懒不想写完整的标签。但是wp-syntax只支持类似&#60;pre lang=”language” line=”1&#8243;&#62;&#60;/pre&#62;之类的标签。只好想法去修改了，但是手工修改的工作量太大，于是继续想懒办法。<br />
　　解决的方法肯定是正则表达式了。所以用php写了个，数据库就按照wp的结构来。下面是代码：<br />
<span id="more-299"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #000000; font-weight: bold;">&#60;?php</span>
	<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#34;localhost&#038;qu</span></pre></div></div><p>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>　　实在受不了syntax highlighter的速度，所以暂时去找了个wp-syntax高亮插件来代替。问题来了，我之前使用时标签都是类似：［c］［/c］，［php］［/php］的，当时偷懒不想写完整的标签。但是wp-syntax只支持类似&lt;pre lang=”language” line=”1&#8243;&gt;&lt;/pre&gt;之类的标签。只好想法去修改了，但是手工修改的工作量太大，于是继续想懒办法。<br />
　　解决的方法肯定是正则表达式了。所以用php写了个，数据库就按照wp的结构来。下面是代码：<br />
<span id="more-299"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span> <span style="color: #339933;">,</span>  <span style="color: #0000ff;">&quot;mysqlname&quot;</span> <span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;passwd&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;can't connect to server&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//这句很关键，如果不设定，读取的全部是乱码，update后数据库中保存的也就成乱码了。</span>
	<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SET NAMES 'UTF8'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dbname&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//修改所有文章.</span>
	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select ID ,post_content from wp_posts&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span>MYSQL_ASSOC<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$rst</span> <span style="color: #339933;">=</span> rp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;post_content&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;ID&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$sqlupdate</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;update wp_posts set post_content = '<span style="color: #006699; font-weight: bold;">$rst</span>' where ID = <span style="color: #006699; font-weight: bold;">$id</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sqlupdate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #666666; font-style: italic;">//sleep(10);这句话如果有的话，执行时间过长。超过了30s的最大执行时间。没找到怎么取消这个时间限制。</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;ok&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//下面是只修改其中一篇文章时的代码.</span>
<span style="color: #666666; font-style: italic;">/*
	$result = mysql_query(&quot;select ID,post_content from wp_posts where ID=197&quot;);
	$row = mysql_fetch_row($result);
	$id = $row[0];	//ID
	$rst = rp($row[1]);//post_content
	$sqlupdate = &quot;update wp_posts set post_content = '$rst' where ID = $id&quot;;
	mysql_query($sqlupdate);
&nbsp;
	echo &quot;ok&quot;; 
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> rp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$rst</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
    <span style="color: #000088;">$pattern</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
        <span style="color: #0000ff;">&quot;/\[c\](.*?)\[\/c\]/is&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;/\[cpp\](.*?)\[\/cpp\]/is&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;/\[php\](.*?)\[\/php\]/is&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;/\[css\](.*?)\[\/css\]/is&quot;</span><span style="color: #339933;">,</span>  
        <span style="color: #0000ff;">&quot;/\[html\](.*?)\[\/html\]/is&quot;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #000088;">$replace</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>c<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>cpp<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>php<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>css<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>html<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span>  <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pattern</span><span style="color: #339933;">,</span><span style="color: #000088;">$replace</span><span style="color: #339933;">,</span><span style="color: #000088;">$rst</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;">?&gt;</span></pre></div></div>

<p>　　你看到的我现在的文章，就是用这个方法修改的。不过，遇到点小问题，有几篇竟然没有转换过去，而当我用修改单篇文章的方式修改时又可以，难道是因为我执行时间太短，还是mysql请求太频繁？<br />
　　早上4点20了，要睡了额。</p>
<p>　　<strong>随笔</strong>：很喜欢<a href="http://mindhacks.cn/">刘未鹏大师</a>的一幅画。<br />
<div id="attachment_300" class="wp-caption alignnone" style="width: 310px"><a href="http://www.boluor.com/wp-content/uploads/2009/08/paradoxoflearning-thumb.jpg"><img src="http://www.boluor.com/wp-content/uploads/2009/08/paradoxoflearning-thumb-300x182.jpg" alt="寻找什么和找到了什么" title="paradoxoflearning-thumb" width="300" height="182" class="size-medium wp-image-300" /></a><p class="wp-caption-text">寻找什么和找到了什么</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boluor.com/update-tags-of-posts-in-batch.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>wordpress纠结笔记之评论表情</title>
		<link>http://www.boluor.com/note-about-wordpress-comment-smiles.html</link>
		<comments>http://www.boluor.com/note-about-wordpress-comment-smiles.html#comments</comments>
		<pubDate>Tue, 18 Aug 2009 09:17:30 +0000</pubDate>
		<dc:creator>boluor</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.boluor.com/?p=278</guid>
		<description><![CDATA[<p>　　之前在life-studio的BLOG上看到一篇文章介绍<a href="http://wange.im/expression-without-plugins-in-wordpress.html">WordPress 非插件调用表情符</a>.按照其中的提示修改后，发现我还是用不了表情符号。而且很奇怪的是，他的代码中只有如何将显示的表情符号转换为相应的文字符号，没有代码处理将文字符号转换为图片。后来问了才知道，原来wordpress又有默认的处理，将一堆的表情符号转换为相应的图片，不用我们另写代码处理。</p>
<p>　　继续测试，发现显示出来还是文字符号。郁闷，决定自己写代码实现。</p>
<p>　　学了几天正则表达式后，我决定在评论提交到服务器后将这些文字符号替换成相应的图片标签。wordpress的评论提交到了根目录下的wp-comments-post.php中，&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>　　之前在life-studio的BLOG上看到一篇文章介绍<a href="http://wange.im/expression-without-plugins-in-wordpress.html">WordPress 非插件调用表情符</a>.按照其中的提示修改后，发现我还是用不了表情符号。而且很奇怪的是，他的代码中只有如何将显示的表情符号转换为相应的文字符号，没有代码处理将文字符号转换为图片。后来问了才知道，原来wordpress又有默认的处理，将一堆的表情符号转换为相应的图片，不用我们另写代码处理。</p>
<p>　　继续测试，发现显示出来还是文字符号。郁闷，决定自己写代码实现。</p>
<p>　　学了几天正则表达式后，我决定在评论提交到服务器后将这些文字符号替换成相应的图片标签。wordpress的评论提交到了根目录下的wp-comments-post.php中，所以在这里面改。找到</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #000088;">$comment_content</span>  <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'comment'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'comment'</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;">null</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>这行代码，在其下面添加几行：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #000088;">$baseurl</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'siteurl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pattern</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/:(.+):/U&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$replacement</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$baseurl</span>/wp-contents/images/smilies/icon_<span style="color: #000099; font-weight: bold;">\$</span>{1}.gif<span style="color: #000099; font-weight: bold;">\&quot;</span> alt=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\$</span>{1}<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$comment_content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pattern</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$replacement</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$comment_content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>　　这样处理的话，用life-studio提供的方法，需要修改下他提供的那个文件。smiley.php。（需要下载的看文章末尾的附件）。就是将其中一些wp可以识别的略写的符号都变成了全称，比如:?:换成了:question:。<br />
<span id="more-278"></span><br />
　　继续测试，我只写了几个表情符号的标签，发现可以显示表情图片了。后来，Sandy发现如果评论中有中文就不能显示了，表情符号直接被过滤掉了。life-studio提醒说，可能是wp-comments-post.php不是utf-8格式的，于是再次将其保存为utf-8。这次我写的评论中有中文字符也没问题了。但是Sandy说他发还是没效果。</p>
<p>　　纠结。。。</p>
<p>　　Sandy说貌似只有你有特权吧，其他人都不能使用表情符号。我就去查，果真如此，wordpress又默认将一些标签给屏蔽了，除管理员以外都不能使用。于是，跑到wp-includes/kses.php中，找到$allowedtags，添加img标签：(a标签默认是允许的)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #0000ff;">'a'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">'href'</span> <span style="color: #339933;">=&gt;</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: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</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: #0000ff;">'img'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'src'</span> <span style="color: #339933;">=&gt;</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: #0000ff;">'alt'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span>	<span style="color: #666666; font-style: italic;">//如果需要更多的属性，在这里添加就可以.</span></pre></td></tr></table></div>

<p>　　也就是说，wordpress是可以定制哪些标签被允许使用的。不过wordpress偷偷作的事情好多好多阿，让我忙乎了差不多一天。</p>
<p><strong>后记：</strong><br />
　　终于搞定了，很无聊，于是随手点击了一个链接进去，突然发现。。。在wordpress设置选项－>撰写栏下面，有个格式化选项，第一个选项就是：转换如 <img src='http://www.boluor.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  和 <img src='http://www.boluor.com/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' />  的文字表情符号为图像，我没有打勾。。。囧阿。之前以为是一些插件的原因，还一个个的停掉测试了。</p>
<p>　　这一番纠结，虽然学了些东西。不过，我更应该考虑的是Sandy的建议了，wordpress其实并不适合我，它不能让我学到一个博客的底层，太复杂太庞大，我学到的不过是wp的结构和一大堆它提供的函数库罢了，而对于我学html,php,mysql等等，并没有大的提升。其实一个小博客，一个不完善，不牛X的博客才更适合我用。</p>
<p><em>下载附件看这里：</em><br />
<a href='http://www.boluor.com/wp-content/uploads/2009/08/smiley.php.zip'>smiley.php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boluor.com/note-about-wordpress-comment-smiles.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Ubuntu下php使用GD库笔记</title>
		<link>http://www.boluor.com/using-php-gd-library-notes-under-ubuntu.html</link>
		<comments>http://www.boluor.com/using-php-gd-library-notes-under-ubuntu.html#comments</comments>
		<pubDate>Sat, 30 May 2009 02:45:42 +0000</pubDate>
		<dc:creator>boluor</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.boluor.com/?p=99</guid>
		<description><![CDATA[<p>    准备给博客写个验证码的，但是在使用GD库生成图片的时候，问题多多，还好现在算是解决了一些。写点下来方便朋友查阅吧，省得像我一样海搜了两天。</p>
<p>    首先是查看GD库有没有被正确的安装和加载.通过gd_info()可以看，或者phpinfo。在phpinfo中可以看到gd一栏，然后版本如果是bundled (2.0.34 compatible) 的话，是从php4.3之后开始绑定的。如果没有的话，可以用命令安装一个:<br />
sudo apt-get install php5-gd.或者为了安装完整版本的,在源列表中添加两行：<br />
deb http://packages.dotdeb.org stable all<br />
deb-src http:/&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>    准备给博客写个验证码的，但是在使用GD库生成图片的时候，问题多多，还好现在算是解决了一些。写点下来方便朋友查阅吧，省得像我一样海搜了两天。</p>
<p>    首先是查看GD库有没有被正确的安装和加载.通过gd_info()可以看，或者phpinfo。在phpinfo中可以看到gd一栏，然后版本如果是bundled (2.0.34 compatible) 的话，是从php4.3之后开始绑定的。如果没有的话，可以用命令安装一个:<br />
sudo apt-get install php5-gd.或者为了安装完整版本的,在源列表中添加两行：<br />
deb http://packages.dotdeb.org stable all<br />
deb-src http://packages.dotdeb.org stable all<br />
    然后升级下：sudo apt-get update. 再安装php5-gd.</p>
<p>    网上有说，安装完成后php.ini会更新，但是我的并没有。搜到gd.so在/usr/lib/php5/20060613+lfs/下,php.ini在/etc/php5/apach2下.于是手动修改php.ini。在其中修改extension_dir=”/usr/lib/php5/20060613+lfs/”,再添加一行extension=gd.so.之后重启apach2:  sudo /etc/init.d/apach2 restart。</p>
<p>    这些完成后可以写个测试的小程序。我使用的是php手册上的例子.文件名为pic.php。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type:image/png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$im</span><span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">300</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$bg_color</span><span style="color: #339933;">=</span>  <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$text_color</span><span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">23</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">14</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">91</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;A Simple Text String&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text_color</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>     浏览器中打开时，开始遇到了些问题。发现提示我下载文件，下载后用gvim打开发现是乱码，不过其中可以看到PNG字样，猜想这应该就是png图像的二进制数据，不过没有被浏览器识别。用ultraedit和其他的png图像对比后，发现PNG图像头都相同，只是结尾多了四个字节。不过更名为pic.png后可以用图像查看器打开。</p>
<p>     继续搜，最后在phpchina论坛上看到了很多人问这个问题。找到了一个貌似答案的说法。说是这个php代码是生成图片的，所以不要在php代码之前输出任何东西，包括空格。试了下，果然可以了。不过需要先关闭浏览器，再打开，不然浏览器输出的是缓存的东西。在另一个文件test.php中用img的src属性调用src=”pic.php”,这个显示正常。所以我觉得，如果需要用gd库生成图片的，最好生成图片的文件单独出来。</p>
<p>     终于纠结完了，开始写验证码。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.boluor.com/using-php-gd-library-notes-under-ubuntu.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>php+mysql+ajax实现留言本</title>
		<link>http://www.boluor.com/php-mysql-ajax-guestbook.html</link>
		<comments>http://www.boluor.com/php-mysql-ajax-guestbook.html#comments</comments>
		<pubDate>Fri, 08 May 2009 00:34:47 +0000</pubDate>
		<dc:creator>boluor</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.boluor.com/blog/?p=34</guid>
		<description><![CDATA[<p>Php+mysql+ajax 实现留言本</p>
<p>闲着无聊，写了个简易的留言本，写下总结吧。</p>
<p>留言本的逻辑很简单，在浏览时将所有的留言显示出来，当用户点击提交新的留言时，将其保存到数据库中。如果不用ajax，那每次更新页面都需要刷新页面，而且需要从服务器将所有的数据down下来，一个增大了服务器的压力，二个给用户很不好的使用体验。所以用ajax来实现异步提交，而且新增的页面上提交的内容，也不需要再从服务器上再down下来，直接更新局部页面即可。</p>
<p>wordpress这个编辑器真是垃圾啊,每次修改code的时候,整个就乱了.代码的缩进就全没了。经过几次折腾后,还是决定提供下载吧&#8230;</p>
<p><a href="http://www.boluor.com/wp-content/uploads/2009/05/phpmysqlajaxe79599e8a880e69cac.rar">php+mysql+a</a>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Php+mysql+ajax 实现留言本</p>
<p>闲着无聊，写了个简易的留言本，写下总结吧。</p>
<p>留言本的逻辑很简单，在浏览时将所有的留言显示出来，当用户点击提交新的留言时，将其保存到数据库中。如果不用ajax，那每次更新页面都需要刷新页面，而且需要从服务器将所有的数据down下来，一个增大了服务器的压力，二个给用户很不好的使用体验。所以用ajax来实现异步提交，而且新增的页面上提交的内容，也不需要再从服务器上再down下来，直接更新局部页面即可。</p>
<p>wordpress这个编辑器真是垃圾啊,每次修改code的时候,整个就乱了.代码的缩进就全没了。经过几次折腾后,还是决定提供下载吧&#8230;</p>
<p><a href="http://www.boluor.com/wp-content/uploads/2009/05/phpmysqlajaxe79599e8a880e69cac.rar">php+mysql+ajax留言本</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boluor.com/php-mysql-ajax-guestbook.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

