<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>想当摄影师的程序员 &#187; 编程</title>
	<atom:link href="http://blog.iworm.net/category/%e7%bc%96%e7%a8%8b/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.iworm.net</link>
	<description>争取不惑之年成为一名自由摄影师</description>
	<lastBuildDate>Tue, 10 Jan 2012 04:09:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/cn/</creativeCommons:license>
		<item>
		<title>升级到ASP.NET 4.0后JS报错的解决办法</title>
		<link>http://blog.iworm.net/2011/07/26/%e5%8d%87%e7%ba%a7%e5%88%b0asp-net-4-0%e5%90%8ejs%e6%8a%a5%e9%94%99%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/</link>
		<comments>http://blog.iworm.net/2011/07/26/%e5%8d%87%e7%ba%a7%e5%88%b0asp-net-4-0%e5%90%8ejs%e6%8a%a5%e9%94%99%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 14:05:40 +0000</pubDate>
		<dc:creator>iworm</dc:creator>
				<category><![CDATA[编程]]></category>

		<guid isPermaLink="false">http://blog.iworm.net/?p=904</guid>
		<description><![CDATA[升级到ASP.NET4.0之后, 有同事打开HRM就报JS错误. Debug进去会看到错误停留在 但是为什么其他同事都是正常的呢? 查看登录页面的源代码之后, 发现一个特殊的标签: &#60;div class=&#8221;aspNetHidden&#8221;&#62; 搜索之后,  看到了这个页面http://msdn.microsoft.com/en-us/library/s57a598e.aspx 原来ASP.NET4.0为了更好的遵循html标准, 删除了form的name属性, 所以登录时这个脚本报错. 解决办法有两个: 1.       把document.Login.txtPassword改成document.getElementById(“txtPassword”) 2.       开启ASP.NET4.0中的渲染兼容模式(web.config): controlRenderingCompatibilityVersion=&#8221;3.5&#8243; 第一种是一劳永逸的写法, 改写不标准的js代码. 但是工作量很大, 也需要额外的测试工作. 第二种就比较偷懒了, 让IIS仍然以ASP.NET3.5的渲染模式输出页面. 这样仍然会保留form的name属性 看下来, ASP.NET4.0比较3.5 做了2点改动(对我们工程来说): 1.       3.5会给table和img增加一个border=”0”属性. 4.0认为border应该是css控制的, 所以不自动增加这个属性 2.       3.5会给form一个id和name. 4.0只会给id, 而删除name属性 更多的改动请参考上面的链接. 建议: HRM里面员工列表, &#8230; <a href="http://blog.iworm.net/2011/07/26/%e5%8d%87%e7%ba%a7%e5%88%b0asp-net-4-0%e5%90%8ejs%e6%8a%a5%e9%94%99%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>升级到ASP.NET4.0之后, 有同事打开HRM就报JS错误.</p>
<p><a href="http://photos.iworm.net/photos/i-j2rbrKr/0/M/i-j2rbrKr-X3.png" target="_blank"><img class="alignnone" src="http://photos.iworm.net/photos/i-j2rbrKr/0/M/i-j2rbrKr-M.png" alt="" width="600" height="365" /></a></p>
<p>Debug进去会看到错误停留在</p>
<p><a href="http://photos.iworm.net/photos/i-hH59tkJ/0/M/i-hH59tkJ-X3.png" target="_blank"><img class="alignnone" src="http://photos.iworm.net/photos/i-hH59tkJ/0/M/i-hH59tkJ-M.png" alt="" width="411" height="119" /></a></p>
<p>但是为什么其他同事都是正常的呢?</p>
<p>查看登录页面的源代码之后, 发现一个特殊的标签: &lt;div class=&#8221;aspNetHidden&#8221;&gt;</p>
<p>搜索之后,  看到了这个页面<a href="http://msdn.microsoft.com/en-us/library/s57a598e.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/s57a598e.aspx </a></p>
<p>原来ASP.NET4.0为了更好的遵循html标准, 删除了form的name属性, 所以登录时这个脚本报错.</p>
<p>解决办法有两个:</p>
<p>1.       把document.Login.txtPassword改成document.getElementById(“txtPassword”)</p>
<p>2.       开启ASP.NET4.0中的渲染兼容模式(web.config): controlRenderingCompatibilityVersion=&#8221;3.5&#8243;<br />
<a href="http://photos.iworm.net/photos/i-xNDrKJv/0/M/i-xNDrKJv-X3.png" target="_blank"><img class="alignnone" src="http://photos.iworm.net/photos/i-xNDrKJv/0/M/i-xNDrKJv-M.png" alt="" width="600" height="111" /></a></p>
<p>第一种是一劳永逸的写法, 改写不标准的js代码. 但是工作量很大, 也需要额外的测试工作.</p>
<p>第二种就比较偷懒了, 让IIS仍然以ASP.NET3.5的渲染模式输出页面. 这样仍然会保留form的name属性</p>
<p>看下来, ASP.NET4.0比较3.5 做了2点改动(对我们工程来说):</p>
<p>1.       3.5会给table和img增加一个border=”0”属性. 4.0认为border应该是css控制的, 所以不自动增加这个属性</p>
<p>2.       3.5会给form一个id和name. 4.0只会给id, 而删除name属性</p>
<p>更多的改动请参考上面的链接.</p>
<p><strong>建议: HRM里面员工列表, 人事信息等诸多模块中都有这些不规范的js写法. 大家以后写js的时候尽量用jquery或者dom函数, 而不要用form的name获取元素</strong></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.iworm.net%2F2011%2F07%2F26%2F%25e5%258d%2587%25e7%25ba%25a7%25e5%2588%25b0asp-net-4-0%25e5%2590%258ejs%25e6%258a%25a5%25e9%2594%2599%25e7%259a%2584%25e8%25a7%25a3%25e5%2586%25b3%25e5%258a%259e%25e6%25b3%2595%2F&amp;title=%E5%8D%87%E7%BA%A7%E5%88%B0ASP.NET%204.0%E5%90%8EJS%E6%8A%A5%E9%94%99%E7%9A%84%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95" id="wpa2a_2"><img src="http://blog.iworm.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.iworm.net/2011/07/26/%e5%8d%87%e7%ba%a7%e5%88%b0asp-net-4-0%e5%90%8ejs%e6%8a%a5%e9%94%99%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/cn/</creativeCommons:license>
	</item>
		<item>
		<title>IIS 7.5 (Windows 2008) 上运行ASP.NET 4.0程序报404错误的解决办法</title>
		<link>http://blog.iworm.net/2011/07/26/iis-7-5-windows-2008-%e4%b8%8a%e8%bf%90%e8%a1%8casp-net-4-0%e7%a8%8b%e5%ba%8f%e6%8a%a5404%e9%94%99%e8%af%af%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/</link>
		<comments>http://blog.iworm.net/2011/07/26/iis-7-5-windows-2008-%e4%b8%8a%e8%bf%90%e8%a1%8casp-net-4-0%e7%a8%8b%e5%ba%8f%e6%8a%a5404%e9%94%99%e8%af%af%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 13:59:24 +0000</pubDate>
		<dc:creator>iworm</dc:creator>
				<category><![CDATA[编程]]></category>

		<guid isPermaLink="false">http://blog.iworm.net/?p=900</guid>
		<description><![CDATA[起因 周四我拿到一台Windows 2008的虚拟机，准备在上面部署一个ASP.NET站点。 我把本地的站点编译好之后，删除了所有的.cs文件，然后传到虚拟机上。 虚拟机上IIS版本是7.5，安装了.Net Framework 4.0，在IIS中开启了对ASP.NET 的支持。按理说就能运行HRM了。 但是运行时，IE提示404错误，也就是找不到网页。这可奇怪了，明明存在的页面，为什么找不到呢？ 尝试 我试着打开一个xml文件，打开了。又把default.aspx改名为default.html，也能打开，为什么偏偏default.aspx提示404呢？ 此时打开IIS的Log文件，看不出任何异常。 2011-05-22 04:29:23 ::1 GET /hrp/ &#8211; 80 &#8211; ::1 Mozilla/4.0+(compatible;+MSIE+8.0;+Windows+NT+6.1;+WOW64;+Trident/4.0;+SLCC2;+.NET+CLR+2.0.50727;+.NET+CLR+3.5.30729;+.NET+CLR+3.0.30729;+.NET4.0C;+.NET4.0E) 404 0 0 7656 彻底没辙了。 于是乎，google一下，看看其他人遇到过类似的问题吗。还真有，不过他们的解决办法都不适合我。 无意中发现 无意中发现，原来IIS7可以装一个叫Tracing的服务。 装好之后，选择需要跟踪的站点，点击图中右下角所示的Failed Request Tracing… 开启跟踪，并设定日志目录。 再次尝试打开aspx文件，然后查看日志。 逐步查看日志内容，会发现一个叫GENERAL RESPONSE ENTITY BUFFER的节，内容跟我们看到的404页面差不多。 真正原因 &#8230; <a href="http://blog.iworm.net/2011/07/26/iis-7-5-windows-2008-%e4%b8%8a%e8%bf%90%e8%a1%8casp-net-4-0%e7%a8%8b%e5%ba%8f%e6%8a%a5404%e9%94%99%e8%af%af%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>起因</strong></p>
<p>周四我拿到一台Windows 2008的虚拟机，准备在上面部署一个ASP.NET站点。</p>
<p>我把本地的站点编译好之后，删除了所有的.cs文件，然后传到虚拟机上。</p>
<p>虚拟机上IIS版本是7.5，安装了.Net Framework 4.0，在IIS中开启了对ASP.NET</p>
<p>的支持。按理说就能运行HRM了。</p>
<p>但是运行时，IE提示404错误，也就是找不到网页。这可奇怪了，明明存在的页面，为什么找不到呢？</p>
<p><a href="http://photos.iworm.net/photos/i-HLVcJ2b/0/M/i-HLVcJ2b-X3.png" target="_blank"><img class="alignnone" src="http://photos.iworm.net/photos/i-HLVcJ2b/0/M/i-HLVcJ2b-M.png" alt="" width="600" height="257" /></a></p>
<p><strong>尝试</strong></p>
<p>我试着打开一个xml文件，打开了。又把default.aspx改名为default.html，也能打开，为什么偏偏default.aspx提示404呢？</p>
<p>此时打开IIS的Log文件，看不出任何异常。</p>
<p>2011-05-22 04:29:23 ::1 GET /hrp/ &#8211; 80 &#8211; ::1 Mozilla/4.0+(compatible;+MSIE+8.0;+Windows+NT+6.1;+WOW64;+Trident/4.0;+SLCC2;+.NET+CLR+2.0.50727;+.NET+CLR+3.5.30729;+.NET+CLR+3.0.30729;+.NET4.0C;+.NET4.0E) 404 0 0 7656</p>
<p>彻底没辙了。</p>
<p>于是乎，google一下，看看其他人遇到过类似的问题吗。还真有，不过他们的解决办法都不适合我。</p>
<p><strong>无意中发现</strong></p>
<p>无意中发现，原来IIS7可以装一个叫Tracing的服务。</p>
<p><a href="http://photos.iworm.net/photos/i-tK29jPn/0/M/i-tK29jPn-X3.png" target="_blank"><img class="alignnone" src="http://photos.iworm.net/photos/i-tK29jPn/0/M/i-tK29jPn-M.png" alt="" width="600" height="411" /></a></p>
<p><a href="http://photos.iworm.net/photos/i-5mVJT5k/0/M/i-5mVJT5k-X3.png" target="_blank"><img class="alignnone" src="http://photos.iworm.net/photos/i-5mVJT5k/0/M/i-5mVJT5k-M.png" alt="" width="600" height="447" /></a></p>
<p>装好之后，选择需要跟踪的站点，点击图中右下角所示的Failed Request Tracing…</p>
<p><a href="http://photos.iworm.net/photos/i-zQ2Q92N/0/M/i-zQ2Q92N-X3.png" target="_blank"><img class="alignnone" src="http://photos.iworm.net/photos/i-zQ2Q92N/0/M/i-zQ2Q92N-M.png" alt="" width="600" height="362" /></a></p>
<p>开启跟踪，并设定日志目录。</p>
<p><img class="alignnone" src="http://photos.iworm.net/photos/i-h5dDttg/0/M/i-h5dDttg-M.png" alt="" width="408" height="245" /></p>
<p>再次尝试打开aspx文件，然后查看日志。</p>
<p>逐步查看日志内容，会发现一个叫GENERAL RESPONSE ENTITY BUFFER的节，内容跟我们看到的404页面差不多。</p>
<p><a href="http://photos.iworm.net/photos/i-dfwGhfM/0/M/i-dfwGhfM-X3.png" target="_blank"><img class="alignnone" src="http://photos.iworm.net/photos/i-dfwGhfM/0/M/i-dfwGhfM-M.png" alt="" width="600" height="442" /></a></p>
<p><strong>真正原因</strong></p>
<p>发现后面多了一些.NET的错误，终于发现，原来发生404错误的真实原因是少了一个叫ATSModuleSetUp.aspx的文件，缺少这个文件会引起default.aspx错误的元凶在于Spring.net，可能它会读取所有aspx文件，以便注入。</p>
<p>重新部署一下站点，问题解决。</p>
<p><strong>推论</strong></p>
<p>1. 404错误提示信息还是很有用的，不过很隐晦，它说HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed。</p>
<p>2. 对于所有web上的错误，最好查看显示页面的源文件，即使是看似标准的404页面也要查看源文件。上面的那些.NET错误信息虽说是在Tracing的Log中发现的，但是同样存在于404页面的源文件中。。。</p>
<p>3. 发生这种错误后，应该写个Hello，World程序来测试一下IIS，就不用绕这么多弯路了，不过现在也学到了如何使用Tracing功能</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.iworm.net%2F2011%2F07%2F26%2Fiis-7-5-windows-2008-%25e4%25b8%258a%25e8%25bf%2590%25e8%25a1%258casp-net-4-0%25e7%25a8%258b%25e5%25ba%258f%25e6%258a%25a5404%25e9%2594%2599%25e8%25af%25af%25e7%259a%2584%25e8%25a7%25a3%25e5%2586%25b3%25e5%258a%259e%25e6%25b3%2595%2F&amp;title=IIS%207.5%20%28Windows%202008%29%20%E4%B8%8A%E8%BF%90%E8%A1%8CASP.NET%204.0%E7%A8%8B%E5%BA%8F%E6%8A%A5404%E9%94%99%E8%AF%AF%E7%9A%84%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95" id="wpa2a_4"><img src="http://blog.iworm.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.iworm.net/2011/07/26/iis-7-5-windows-2008-%e4%b8%8a%e8%bf%90%e8%a1%8casp-net-4-0%e7%a8%8b%e5%ba%8f%e6%8a%a5404%e9%94%99%e8%af%af%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/cn/</creativeCommons:license>
	</item>
		<item>
		<title>WordPress及插件不能自动升级的解决办法</title>
		<link>http://blog.iworm.net/2010/12/31/wordpress%e5%8f%8a%e6%8f%92%e4%bb%b6%e4%b8%8d%e8%83%bd%e8%87%aa%e5%8a%a8%e5%8d%87%e7%ba%a7%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/</link>
		<comments>http://blog.iworm.net/2010/12/31/wordpress%e5%8f%8a%e6%8f%92%e4%bb%b6%e4%b8%8d%e8%83%bd%e8%87%aa%e5%8a%a8%e5%8d%87%e7%ba%a7%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/#comments</comments>
		<pubDate>Fri, 31 Dec 2010 01:56:06 +0000</pubDate>
		<dc:creator>iworm</dc:creator>
				<category><![CDATA[编程]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[permission]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.iworm.net/?p=777</guid>
		<description><![CDATA[WordPress提示你有插件需要更新的时候, 点击自动更新按钮, 但是会让你填写FTP信息. 这是因为Wordpress在判断权限时发生了问题, 它会判断/wp-admin/update.php这个文件的owner是不是当前的apache进程, 如果是就能更新(更新时还是需要相应文件夹和文件的权限), 如果不是就提示你输入FTP信息. 所以如果可能的话, 修改这个文件的owner为apache进程即可. chown www-data.www-data ./wp-admin/update.php]]></description>
			<content:encoded><![CDATA[<p>WordPress提示你有插件需要更新的时候, 点击自动更新按钮, 但是会让你填写FTP信息.</p>
<p>这是因为Wordpress在判断权限时发生了问题, 它会判断/wp-admin/update.php这个文件的owner是不是当前的apache进程, 如果是就能更新(更新时还是需要相应文件夹和文件的权限), 如果不是就提示你输入FTP信息.</p>
<p>所以如果可能的话, 修改这个文件的owner为apache进程即可.</p>
<p><code>chown www-data.www-data ./wp-admin/update.php</code></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.iworm.net%2F2010%2F12%2F31%2Fwordpress%25e5%258f%258a%25e6%258f%2592%25e4%25bb%25b6%25e4%25b8%258d%25e8%2583%25bd%25e8%2587%25aa%25e5%258a%25a8%25e5%258d%2587%25e7%25ba%25a7%25e7%259a%2584%25e8%25a7%25a3%25e5%2586%25b3%25e5%258a%259e%25e6%25b3%2595%2F&amp;title=WordPress%E5%8F%8A%E6%8F%92%E4%BB%B6%E4%B8%8D%E8%83%BD%E8%87%AA%E5%8A%A8%E5%8D%87%E7%BA%A7%E7%9A%84%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95" id="wpa2a_6"><img src="http://blog.iworm.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.iworm.net/2010/12/31/wordpress%e5%8f%8a%e6%8f%92%e4%bb%b6%e4%b8%8d%e8%83%bd%e8%87%aa%e5%8a%a8%e5%8d%87%e7%ba%a7%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/cn/</creativeCommons:license>
	</item>
		<item>
		<title>PHP substr 截取 UTF8字符串乱码的解决</title>
		<link>http://blog.iworm.net/2010/03/20/php-substr-%e6%88%aa%e5%8f%96-utf8%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b9%b1%e7%a0%81%e7%9a%84%e8%a7%a3%e5%86%b3/</link>
		<comments>http://blog.iworm.net/2010/03/20/php-substr-%e6%88%aa%e5%8f%96-utf8%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b9%b1%e7%a0%81%e7%9a%84%e8%a7%a3%e5%86%b3/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 17:18:33 +0000</pubDate>
		<dc:creator>iworm</dc:creator>
				<category><![CDATA[编程]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[utf8]]></category>

		<guid isPermaLink="false">http://blog.iworm.net/?p=681</guid>
		<description><![CDATA[PHP的substr方法可以按照字节来截取字符串, 对于英文来说是没问题的. 因为一个英文字符只占一个字节. 但是对于截取UTF8编码的中文就会存在问题. 比如: var $str = &#8216;我爱twitter哈哈&#8217;; echo substr($str, 0, 1); 就会出现一个乱字符, 因为在php中, utf8编码的中文是占3个字节, 单单只取一个字节肯定是不行啦. 如果: echo substr($str, 0, 3)就会出现&#8221;我&#8221; echo substr($str, 0, 9) 会出现&#8221;我爱twi&#8221; 在中英文混排的时候, 这个函数就显得无能为力了. google了一下, 发现很多人写了替代方法, 比如自己去实现一个substr, 里面写循环. 这样肯定效率低下, 直接用substr的复杂度是1, 而自己写循环, 复杂度就是n了. 后来找到了Wikipedia的条目, 发现原来3字节的utf8编码是有规律的. 一个非英文字符的3-bytes &#8230; <a href="http://blog.iworm.net/2010/03/20/php-substr-%e6%88%aa%e5%8f%96-utf8%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b9%b1%e7%a0%81%e7%9a%84%e8%a7%a3%e5%86%b3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>PHP的substr方法可以按照字节来截取字符串, 对于英文来说是没问题的. 因为一个英文字符只占一个字节.<br />
但是对于截取UTF8编码的中文就会存在问题.<br />
比如:<br />
var $str = &#8216;我爱twitter哈哈&#8217;;<br />
echo substr($str, 0, 1);<br />
就会出现一个乱字符, 因为在php中, utf8编码的中文是占3个字节, 单单只取一个字节肯定是不行啦.<br />
如果: echo substr($str, 0, 3)就会出现&#8221;我&#8221;<br />
echo substr($str, 0, 9) 会出现&#8221;我爱twi&#8221;</p>
<p>在中英文混排的时候, 这个函数就显得无能为力了.</p>
<p>google了一下, 发现很多人写了替代方法, 比如自己去实现一个substr, 里面写循环.<br />
这样肯定效率低下, 直接用substr的复杂度是1, 而自己写循环, 复杂度就是n了.</p>
<p>后来找到了<a href="http://en.wikipedia.org/wiki/UTF-8">Wikipedia的条目</a>, 发现原来3字节的utf8编码是有规律的.<br />
一个非英文字符的3-bytes utf8 编码, 总是以224-239之间的char code开头的, 这就好办了.<br />
思路是这样的:<br />
先用substr截取, 判断截取结果的最后一位是不是在224-239之间, 如果是, 就说明目前取到了3-byte utf8编码的第一位, 那么只需要把计划截取的长度-1即可.<br />
如果截取结果的最后一位之前一位在224-239之间, 就说明目前取到了3-byte utf8编码的第二位, 只需要将计划截取的长度-2即可.</p>
<p>下面是代码:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> csubstr<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$beginIndex</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</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;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$beginIndex</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$char</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$beginIndex</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$length</span> <span style="color: #339933;">-</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: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$char</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">224</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$char</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">239</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: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$beginIndex</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</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: #b1b100;">return</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$char</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$beginIndex</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$length</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</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;">$char</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">224</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$char</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">239</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: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$beginIndex</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$beginIndex</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.iworm.net%2F2010%2F03%2F20%2Fphp-substr-%25e6%2588%25aa%25e5%258f%2596-utf8%25e5%25ad%2597%25e7%25ac%25a6%25e4%25b8%25b2%25e4%25b9%25b1%25e7%25a0%2581%25e7%259a%2584%25e8%25a7%25a3%25e5%2586%25b3%2F&amp;title=PHP%20substr%20%E6%88%AA%E5%8F%96%20UTF8%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B9%B1%E7%A0%81%E7%9A%84%E8%A7%A3%E5%86%B3" id="wpa2a_8"><img src="http://blog.iworm.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.iworm.net/2010/03/20/php-substr-%e6%88%aa%e5%8f%96-utf8%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b9%b1%e7%a0%81%e7%9a%84%e8%a7%a3%e5%86%b3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/cn/</creativeCommons:license>
	</item>
		<item>
		<title>How to: Implement Dynamic Route in CakePHP</title>
		<link>http://blog.iworm.net/2009/12/17/how-to-implement-dynamic-route-in-cakephp/</link>
		<comments>http://blog.iworm.net/2009/12/17/how-to-implement-dynamic-route-in-cakephp/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 16:53:30 +0000</pubDate>
		<dc:creator>iworm</dc:creator>
				<category><![CDATA[编程]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[route]]></category>

		<guid isPermaLink="false">http://blog.iworm.net/?p=668</guid>
		<description><![CDATA[I&#8217;ve found a method to implement Dynamic Route in CakePHP. If we develop a CMS program using CakePHP, we often let people to define their menu code. The menu code basically is the URL path. For example: An admin create &#8230; <a href="http://blog.iworm.net/2009/12/17/how-to-implement-dynamic-route-in-cakephp/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve found a method to implement Dynamic Route in CakePHP.<br />
If we develop a CMS program using CakePHP, we often let people to define their menu code. The menu code basically is the URL path.<br />
For example: An admin create a menu named &#8216;Milk Product&#8217;, and give this menu a code &#8216;product&#8217;.<br />
He wish to access this menu via /product</p>
<p>So we can add a static route in routes.php<br />
Router::connect(&#8216;/product&#8217;, array(&#8216;controller&#8217; => &#8216;product&#8217;, &#8216;action&#8217; => &#8216;index&#8217;));</p>
<p>But one day, he want to change the menu code from &#8216;product&#8217; to &#8216;milkproduct&#8217;? What to do then? Ask the site admin to edit the routes.php? Of course not.</p>
<p>We can use the code below to resolve this problem.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$menus</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
Cache<span style="color: #339933;">::</span><span style="color: #004000;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'routemenus'</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;">$menus</span> <span style="color: #339933;">=</span> Cache<span style="color: #339933;">::</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'routemenus'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'load from db'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$menusModel</span> <span style="color: #339933;">=</span> ClassRegistry<span style="color: #339933;">::</span><span style="color: #004000;">init</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Menu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$menus</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$menusModel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'all'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'conditions'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'parent_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Cache<span style="color: #339933;">::</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'routemenus'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$menus</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$menus</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$menuitem</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    Router<span style="color: #339933;">::</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$menuitem</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Menu'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'code'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/:action/*'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'controller'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$menuitem</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'MenuType'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'code'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
Router<span style="color: #339933;">::</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'controller'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'homepage'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>We have 2 menu related tables: menus and menu_types.<br />
Their structure as belows:</p>
<pre>menus
    id
    menu_type_id
    parent_id
    lft
    rght
    code
    name
    created
    modified

menu_types
    id
    code
    name
    created
    modified</pre>
<p>The code in menu_types means the controller name, and the code in menus means the path.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.iworm.net%2F2009%2F12%2F17%2Fhow-to-implement-dynamic-route-in-cakephp%2F&amp;title=How%20to%3A%20Implement%20Dynamic%20Route%20in%20CakePHP" id="wpa2a_10"><img src="http://blog.iworm.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.iworm.net/2009/12/17/how-to-implement-dynamic-route-in-cakephp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/cn/</creativeCommons:license>
	</item>
		<item>
		<title>WordPress不能在别人评论后给我发送邮件的解决办法</title>
		<link>http://blog.iworm.net/2009/06/19/wordpress%e4%b8%8d%e8%83%bd%e5%9c%a8%e5%88%ab%e4%ba%ba%e8%af%84%e8%ae%ba%e5%90%8e%e7%bb%99%e6%88%91%e5%8f%91%e9%80%81%e9%82%ae%e4%bb%b6%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/</link>
		<comments>http://blog.iworm.net/2009/06/19/wordpress%e4%b8%8d%e8%83%bd%e5%9c%a8%e5%88%ab%e4%ba%ba%e8%af%84%e8%ae%ba%e5%90%8e%e7%bb%99%e6%88%91%e5%8f%91%e9%80%81%e9%82%ae%e4%bb%b6%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 15:27:09 +0000</pubDate>
		<dc:creator>iworm</dc:creator>
				<category><![CDATA[编程]]></category>

		<guid isPermaLink="false">http://blog.iworm.net/?p=611</guid>
		<description><![CDATA[这是一个非常诡异的问题. 遇到问题后, 我google了一下. 发现有些人遇到了和我类似的问题. 但是他们的问题原因仅仅是服务器不支持php的mail函数, 他们只需要安装wp mail smtp组件就可以发送了. 而我确定我的服务器支持mail函数. 我对于php还是新手, 还不知道怎么在windows上测试php的mail函数. 所以就只能在本地把文件改改, 然后上传到服务器上做发送邮件测试. WordPress调用的是PHPMailer组件发送邮件, 经过几个小时的调试之后, 我发现问题的原因在于2点: 1. PHPMailer的Sender属性为空. 这个属性为空将直接导致不会发送任何邮件. 2. PHPMail的MailSend方法中是这么调用mail函数的: $rt = @mail($to, $this-&#62;EncodeHeader($this-&#62;SecureHeader($this-&#62;Subject)), $body, $header, $params); 我注意到如果把$this-&#62;EncodeHeader($this-&#62;SecureHeader($this-&#62;Subject))替换成固定的字符串, 并且将Sender属性设置为我的email地址, WordPress就可以给我发送评论邮件了. 关于字符编码的问题我不是很懂, 大概看看这个EncodeHeader函数, 没看懂. $this-&#62;Subject的内容是&#8221;[想当摄影师的程序员] Comment: &#8220;Symbian S60 V3系统不破解也能提升权限&#8221;" 如果直接用var_dump($this-&#62;EncodeHeader($this-&#62;SecureHeader($this-&#62;Subject))), &#8230; <a href="http://blog.iworm.net/2009/06/19/wordpress%e4%b8%8d%e8%83%bd%e5%9c%a8%e5%88%ab%e4%ba%ba%e8%af%84%e8%ae%ba%e5%90%8e%e7%bb%99%e6%88%91%e5%8f%91%e9%80%81%e9%82%ae%e4%bb%b6%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>这是一个非常诡异的问题.</p>
<p>遇到问题后, 我google了一下. 发现有些人遇到了和我类似的问题. 但是他们的问题原因仅仅是服务器不支持php的mail函数, 他们只需要安装wp mail smtp组件就可以发送了.</p>
<p>而我确定我的服务器支持mail函数.</p>
<p>我对于php还是新手, 还不知道怎么在windows上测试php的mail函数. 所以就只能在本地把文件改改, 然后上传到服务器上做发送邮件测试.</p>
<p>WordPress调用的是PHPMailer组件发送邮件, 经过几个小时的调试之后, 我发现问题的原因在于2点:</p>
<p>1. PHPMailer的Sender属性为空. 这个属性为空将直接导致不会发送任何邮件.</p>
<p>2. PHPMail的MailSend方法中是这么调用mail函数的:</p>
<p>$rt = @mail($to, $this-&gt;EncodeHeader($this-&gt;SecureHeader($this-&gt;Subject)), $body, $header, $params);</p>
<p>我注意到如果把$this-&gt;EncodeHeader($this-&gt;SecureHeader($this-&gt;Subject))替换成固定的字符串, 并且将Sender属性设置为我的email地址, WordPress就可以给我发送评论邮件了.</p>
<p>关于字符编码的问题我不是很懂, 大概看看这个EncodeHeader函数, 没看懂.</p>
<p>$this-&gt;Subject的内容是&#8221;[想当摄影师的程序员] Comment: &#8220;Symbian S60 V3系统不破解也能提升权限&#8221;"</p>
<p>如果直接用var_dump($this-&gt;EncodeHeader($this-&gt;SecureHeader($this-&gt;Subject))), 会得到一串加了编码前缀的base64字符串. &#8220;=?utf-8?B?W+aDs+W9k+aRhOW9seW4iOeahOeoi+W6j+WRmF0gTmV3IENvbW1lbnQgT24=?=  =?utf-8?B?OiBTeW1iaWFuIFM2MCBWM+ezu+e7n+S4jeegtOino+S5n+iDveaPkOWNhw==?=  =?utf-8?B?5p2D6ZmQ?=&#8221;</p>
<p>bin2hex函数可以将任意内容转换成十六进制的字符串.</p>
<p>于是我调用了两次bin2hex方法.</p>
<p>var_dump(bin2hex($this-&gt;EncodeHeader($this-&gt;SecureHeader($this-&gt;Subject))))</p>
<p>var_dump(bin2hex(&#8220;=?utf-8?B?W+aDs+W9k+aRhOW9seW4iOeahOeoi+W6j+WRmF0gTmV3IENvbW1lbnQgT24=?= =?utf-8?B?OiBTeW1iaWFuIFM2MCBWM+ezu+e7n+S4jeegtOino+S5n+iDveaPkOWNhw==?= =?utf-8?B?5p2D6ZmQ?=&#8221;))</p>
<p>发现转出来的十六进制码竟然有差别.</p>
<p>3d3f7574662d383f423f572b6144732b57396b2b6152684f573973655734694f6561684f656f692b57366a2b57<br />
526d463067546d563349454e766257316c626e51675432343d3f3d<strong><span style="color: #ff0000;">0a</span></strong>203d3f7574662d383f423f4f694254655<br />
731696157467549464d324d4342574d2b657a752b65376e2b53346a656567744f696e6f2b53356e2b6944766<br />
561506b4f574e68773d3d3f3d<strong><span style="color: #ff0000;">0a</span></strong>203d3f7574662d383f423f35703244365a6d513f3d</p>
<p>3d3f7574662d383f423f572b6144732b57396b2b6152684f573973655734694f6561684f656f692b57366a2b57<br />
526d463067546d563349454e766257316c626e51675432343d3f3d203d3f7574662d383f423f4f694254655<br />
731696157467549464d324d4342574d2b657a752b65376e2b53346a656567744f696e6f2b53356e2b6944766<br />
561506b4f574e68773d3d3f3d203d3f7574662d383f423f35703244365a6d513f3d</p>
<p>你会看到第一个方法比第二个方法多出两个0a</p>
<p>不知道为什么.</p>
<p>为了不使用PHPMailer的EncodeHeader函数, 我调用了PHP自带的函数. 做了以下修改:</p>
<p>$subject = &#8216;=?UTF-8?B?&#8217; . base64_encode($this-&gt;Subject) . &#8216;?=&#8217;;<br />
$rt = @mail($to, $subject, $body, $header, $params);</p>
<p>这样我就可以收到邮件了.</p>
<p>关于刚才说的第一个问题, 我也不清楚是怎么回事.</p>
<p>干脆我就直接给Sender属性赋值好了. 将以下两句加到MailSend函数的开头.</p>
<p>$this-&gt;Sender = &#8216;这里填上自己的email地址&#8217;;</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.iworm.net%2F2009%2F06%2F19%2Fwordpress%25e4%25b8%258d%25e8%2583%25bd%25e5%259c%25a8%25e5%2588%25ab%25e4%25ba%25ba%25e8%25af%2584%25e8%25ae%25ba%25e5%2590%258e%25e7%25bb%2599%25e6%2588%2591%25e5%258f%2591%25e9%2580%2581%25e9%2582%25ae%25e4%25bb%25b6%25e7%259a%2584%25e8%25a7%25a3%25e5%2586%25b3%25e5%258a%259e%25e6%25b3%2595%2F&amp;title=WordPress%E4%B8%8D%E8%83%BD%E5%9C%A8%E5%88%AB%E4%BA%BA%E8%AF%84%E8%AE%BA%E5%90%8E%E7%BB%99%E6%88%91%E5%8F%91%E9%80%81%E9%82%AE%E4%BB%B6%E7%9A%84%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95" id="wpa2a_12"><img src="http://blog.iworm.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.iworm.net/2009/06/19/wordpress%e4%b8%8d%e8%83%bd%e5%9c%a8%e5%88%ab%e4%ba%ba%e8%af%84%e8%ae%ba%e5%90%8e%e7%bb%99%e6%88%91%e5%8f%91%e9%80%81%e9%82%ae%e4%bb%b6%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/cn/</creativeCommons:license>
	</item>
		<item>
		<title>CakePHP报500错误的解决方法</title>
		<link>http://blog.iworm.net/2009/04/29/cakephp%e6%8a%a5500%e9%94%99%e8%af%af%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95/</link>
		<comments>http://blog.iworm.net/2009/04/29/cakephp%e6%8a%a5500%e9%94%99%e8%af%af%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 13:52:52 +0000</pubDate>
		<dc:creator>iworm</dc:creator>
				<category><![CDATA[编程]]></category>

		<guid isPermaLink="false">http://blog.iworm.net/?p=601</guid>
		<description><![CDATA[我把CakePHP做的网站传到主机上, 发现只有首页能打开. 点其他链接都报500错误. 在看不到日志的情况下问题出现的可能性是多种多样的. 后来google一下, 发现有人遇到过类似的问题, 解决方法是换个主机&#8230;&#8230;. 不信邪. 首页能打开就说明我的配置没错, CakePHP是能正常运行的. 可能问题出现在URL的Rewrite上, 于是我尝试使用/index.php?url=service (注: service是controller的名字)来打开, 可以打开. 更加证实了CakePHP是没问题的想法. 于是我就修改了.htaccess. 原来内容是 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] 我改成 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule &#8230; <a href="http://blog.iworm.net/2009/04/29/cakephp%e6%8a%a5500%e9%94%99%e8%af%af%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>我把CakePHP做的网站传到主机上, 发现只有首页能打开. 点其他链接都报500错误. 在看不到日志的情况下问题出现的可能性是多种多样的.<br />
后来google一下, 发现有人遇到过类似的问题, 解决方法是换个主机&#8230;&#8230;.</p>
<p>不信邪. 首页能打开就说明我的配置没错, CakePHP是能正常运行的. 可能问题出现在URL的Rewrite上, 于是我尝试使用/index.php?url=service (注: service是controller的名字)来打开, 可以打开. 更加证实了CakePHP是没问题的想法. 于是我就修改了.htaccess.<br />
原来内容是</p>
<pre>    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]</pre>
<p>我改成</p>
<pre>    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ <span style="color: #ff0000;">/</span>index.php?url=$1 [QSA,L]</pre>
<p>看到吗? 我给index.php前面加了个斜线, 问题解决.<br />
这会是一个很好的解决方法吗? 继续google, 后来在cakephp的官方网站上找到了一个方法.</p>
<pre>    RewriteEngine On
    <span style="color: #ff0000;">RewriteBase /</span>
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]</pre>
<p>参考: <a href="http://planetcakephp.org/aggregator/items/1236-cakephp-500-internal-error">CakePHP: 500 Internal Error</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.iworm.net%2F2009%2F04%2F29%2Fcakephp%25e6%258a%25a5500%25e9%2594%2599%25e8%25af%25af%25e7%259a%2584%25e8%25a7%25a3%25e5%2586%25b3%25e6%2596%25b9%25e6%25b3%2595%2F&amp;title=CakePHP%E6%8A%A5500%E9%94%99%E8%AF%AF%E7%9A%84%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95" id="wpa2a_14"><img src="http://blog.iworm.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.iworm.net/2009/04/29/cakephp%e6%8a%a5500%e9%94%99%e8%af%af%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/cn/</creativeCommons:license>
	</item>
		<item>
		<title>Javascript 排序问题</title>
		<link>http://blog.iworm.net/2008/12/12/javascript-%e6%8e%92%e5%ba%8f%e9%97%ae%e9%a2%98/</link>
		<comments>http://blog.iworm.net/2008/12/12/javascript-%e6%8e%92%e5%ba%8f%e9%97%ae%e9%a2%98/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 08:53:54 +0000</pubDate>
		<dc:creator>iworm</dc:creator>
				<category><![CDATA[编程]]></category>
		<category><![CDATA[compare]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[locale]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://blog.iworm.net/?p=486</guid>
		<description><![CDATA[我们买了个web表格控件, 点击表头可以排序的, 对于英文没问题, 是按照英文字母顺序排的, 但是中文就乱了. 不按拼音顺序, 也不按笔画顺序. 后来在网上找了一下, 发现Javascript的sort方法对于中文是按照内码来排的. 如果想让其按拼音来排, 需要用localCompare 原始顺序是: 猪zhu-1,我wo-2,啊a-3,你ni-4,他ta-5,地di-6 Javascript本身的sort排序后是: 他ta-5,你ni-4,啊a-3,地di-6,我wo-2,猪zhu-1 按照拼音排序结果是: 啊a-3,地di-6,你ni-4,他ta-5,我wo-2,猪zhu-1 具体请看代码 HTML+Cheetah语言: Javascript 排序问题 &#60;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221; &#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&#62; &#60;html xmlns=&#8220;http://www.w3.org/1999/xhtml&#8221;&#62; &#60;head&#62; &#60;meta http-equiv=&#8220;Content-Type&#8221; content=&#8220;text/html; charset=utf-8&#8243; /&#62; &#60;title&#62;Sort Test&#60;/title&#62; &#60;/head&#62; &#8230; <a href="http://blog.iworm.net/2008/12/12/javascript-%e6%8e%92%e5%ba%8f%e9%97%ae%e9%a2%98/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>我们买了个web表格控件, 点击表头可以排序的, 对于英文没问题, 是按照英文字母顺序排的, 但是中文就乱了. 不按拼音顺序, 也不按笔画顺序.</p>
<p>后来在网上找了一下, 发现Javascript的sort方法对于中文是按照内码来排的.</p>
<p>如果想让其按拼音来排, 需要用localCompare</p>
<p>原始顺序是: 猪zhu-1,我wo-2,啊a-3,你ni-4,他ta-5,地di-6</p>
<p>Javascript本身的sort排序后是: 他ta-5,你ni-4,啊a-3,地di-6,我wo-2,猪zhu-1</p>
<p>按照拼音排序结果是: 啊a-3,地di-6,你ni-4,他ta-5,我wo-2,猪zhu-1</p>
<p>具体请看代码</p>
<div style="background: #fdfdfd none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="text-decoration: underline;">HTML+Cheetah语言</span>: <a href="http://www.fayaa.com/code/view/545/">Javascript 排序问题</a></div>
<div class="source" style="font-family: &quot;[object HTMLOptionElement]&quot;,&quot;Lucida Console&quot;,&quot;Courier New&quot;,&quot;Bitstream Vera Sans Mono&quot;; background-color: #f9f7ed;"><span style="color: #008080;">&lt;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221; &#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;</span><br />
<span style="color: #000080; font-weight: bold;">&lt;html</span> <span style="color: #ff0000;">xmlns=</span><span style="color: #0000ff;">&#8220;http://www.w3.org/1999/xhtml&#8221;</span><span style="color: #000080; font-weight: bold;">&gt;</span><br />
<span style="color: #000080; font-weight: bold;">&lt;head&gt;</span><br />
<span style="color: #000080; font-weight: bold;">&lt;meta</span> <span style="color: #ff0000;">http-equiv=</span><span style="color: #0000ff;">&#8220;Content-Type&#8221;</span> <span style="color: #ff0000;">content=</span><span style="color: #0000ff;">&#8220;text/html; charset=utf-8&#8243;</span> <span style="color: #000080; font-weight: bold;">/&gt;</span><br />
<span style="color: #000080; font-weight: bold;">&lt;title&gt;</span>Sort Test<span style="color: #000080; font-weight: bold;">&lt;/title&gt;</span><br />
<span style="color: #000080; font-weight: bold;">&lt;/head&gt;</span></p>
<p><span style="color: #000080; font-weight: bold;">&lt;body&gt;</span><br />
<span style="color: #000080; font-weight: bold;">&lt;script </span><span style="color: #ff0000;">type=</span><span style="color: #0000ff;">&#8220;text/javascript&#8221;</span><span style="color: #000080; font-weight: bold;">&gt;</span><br />
<span style="color: #000080; font-weight: bold;">function</span> mysort()<br />
{<br />
<span style="color: #000080; font-weight: bold;">var</span> s = <span style="color: #0000ff;">&#8220;猪zhu-1,我wo-2,啊a-3,你ni-4,他ta-5,地di-6&#8243;</span>;<br />
alert(<span style="color: #0000ff;">&#8220;The original is:\n&#8221;</span> + s);</p>
<p><span style="color: #000080; font-weight: bold;">var</span> a = s.split(<span style="color: #0000ff;">&#8220;,&#8221;</span>);</p>
<p>a.sort();</p>
<p>alert(<span style="color: #0000ff;">&#8220;This is wrong:\n&#8221;</span> + a);</p>
<p>a.sort(<span style="color: #000080; font-weight: bold;">function</span>(c1, c2)<br />
{<br />
<span style="color: #000080; font-weight: bold;">return</span> c1.localeCompare(c2);<br />
});</p>
<p>alert(<span style="color: #0000ff;">&#8220;This is right:\n&#8221;</span> + a);<br />
}<br />
<span style="color: #000080; font-weight: bold;">&lt;/script&gt;</span><br />
<span style="color: #000080; font-weight: bold;">&lt;input</span> <span style="color: #ff0000;">type=</span><span style="color: #0000ff;">&#8220;button&#8221;</span> <span style="color: #ff0000;">value=</span><span style="color: #0000ff;">&#8220;test&#8221;</span> <span style="color: #ff0000;">onclick=</span><span style="color: #0000ff;">&#8220;mysort()&#8221;</span> <span style="color: #000080; font-weight: bold;">/&gt;</span></p>
<p><span style="color: #000080; font-weight: bold;">&lt;/body&gt;</span><br />
<span style="color: #000080; font-weight: bold;">&lt;/html&gt;</span></div>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.iworm.net%2F2008%2F12%2F12%2Fjavascript-%25e6%258e%2592%25e5%25ba%258f%25e9%2597%25ae%25e9%25a2%2598%2F&amp;title=Javascript%20%E6%8E%92%E5%BA%8F%E9%97%AE%E9%A2%98" id="wpa2a_16"><img src="http://blog.iworm.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.iworm.net/2008/12/12/javascript-%e6%8e%92%e5%ba%8f%e9%97%ae%e9%a2%98/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/cn/</creativeCommons:license>
	</item>
		<item>
		<title>在BlueHost上安装Subversion</title>
		<link>http://blog.iworm.net/2008/10/31/%e5%9c%a8bluehost%e4%b8%8a%e5%ae%89%e8%a3%85subversion/</link>
		<comments>http://blog.iworm.net/2008/10/31/%e5%9c%a8bluehost%e4%b8%8a%e5%ae%89%e8%a3%85subversion/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 10:23:39 +0000</pubDate>
		<dc:creator>iworm</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[bluehost]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.iworm.net/?p=446</guid>
		<description><![CDATA[一开始是按照Bluehost论坛上的方法来安装, 但是发现无法支持http, https协议, 又按照半瓶墨水的方法来安装, 这次支持http协议了, 但是依然不支持https. 后来google了一下, 经过多次摸索, 终于安装成功, 下面分享经验. cd ~ mkdir install mkdir src cd src #下载 wget http://subversion.tigris.org/downloads/subversion-1.6.4.tar.gz wget http://subversion.tigris.org/downloads/subversion-deps-1.6.4.tar.gz wget http://www.openssl.org/source/openssl-0.9.8k.tar.gz tar xzvf openssl-0.9.8k.tar.gz tar xzvf subversion-deps-1.6.4.tar.gz mv subversion-1.6.4 deps tar xzvf subversion-1.6.4.tar.gz #编译OpenSSL cd openssl-0.9.8k &#8230; <a href="http://blog.iworm.net/2008/10/31/%e5%9c%a8bluehost%e4%b8%8a%e5%ae%89%e8%a3%85subversion/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>一开始是按照<a href="http://www.bluehostforum.com/showthread.php?t=12099&amp;highlight=subversion" target="_blank">Bluehost论坛</a>上的方法来安装, 但是发现无法支持http, https协议, 又按照<a href="http://www.2maomao.com/blog/bluehost-svn-64/" target="_blank">半瓶墨水</a>的方法来安装, 这次支持http协议了, 但是依然不支持https.</p>
<p>后来google了一下, 经过多次摸索, 终于安装成功, 下面分享经验.<br />
cd ~<br />
mkdir install<br />
mkdir src<br />
cd src<br />
#下载<br />
wget http://subversion.tigris.org/downloads/subversion-1.6.4.tar.gz<br />
wget http://subversion.tigris.org/downloads/subversion-deps-1.6.4.tar.gz<br />
wget http://www.openssl.org/source/openssl-0.9.8k.tar.gz<br />
tar xzvf openssl-0.9.8k.tar.gz<br />
tar xzvf subversion-deps-1.6.4.tar.gz<br />
mv subversion-1.6.4 deps<br />
tar xzvf subversion-1.6.4.tar.gz</p>
<p>#编译OpenSSL<br />
cd openssl-0.9.8k<br />
./config &#8211;prefix=$HOME/install/openssl<br />
make<br />
make install<br />
cd ..<br />
cd deps</p>
<p>#编译apr<br />
cd apr<br />
./configure &#8211;prefix=$HOME/install/apr LDFLAGS=&#8221;-L/lib64&#8243;<br />
make<br />
make install<br />
cd ..</p>
<p>#编译apr-util<br />
cd apr-util<br />
./configure &#8211;prefix=$HOME/install/apr-util &#8211;with-apr=$HOME/install/apr LDFLAGS=&#8221;-L/lib64&#8243;<br />
make<br />
make install<br />
cd ..</p>
<p>#编译serf<br />
cd serf<br />
./configure &#8211;prefix=$HOME/install/serf &#8211;with-apr=$HOME/install/apr &#8211;with-apr-util=$HOME/install/apr-util &#8211;with-openssl=$HOME/install/openssl LDFLAGS=&#8221;-L/lib64&#8243;<br />
make<br />
make install<br />
cd ..</p>
<p>#编译zlib<br />
cd zlib<br />
./configure &#8211;prefix=$HOME/install/zlib<br />
make<br />
make install<br />
cd ..</p>
<p>#编译neon, subversion是否支持https就看这个组件编译的时候是否支持ssl了, 编译完成后, 你会看到一个summary, 上面明确显示支持ssl就对了<br />
cd neon<br />
./configure &#8211;prefix=$HOME/install/neon &#8211;enable-shared &#8211;enable-ssl &#8211;with-ssl &#8211;with-libs=$HOME/install/openssl  LDFLAGS=&#8221;-L/lib64&#8243;<br />
make<br />
make install<br />
cd ..<br />
cd..</p>
<p>#编译subversion<br />
cd subversion-1.6.4<br />
cp -R ~/src/deps/sqlite-amalgamation ./<br />
./configure &#8211;prefix=$HOME/install/subversion &#8211;without-berkeley-db &#8211;with-zlib=$HOME/install/zlib &#8211;with-apr=$HOME/install/apr &#8211;with-apr-util=$HOME/install/apr-util &#8211;with-serf=$HOME/install/serf &#8211;with-neon=$HOME/install/neon &#8211;with-ssl LDFLAGS=&#8221;-L/lib64&#8243;<br />
make<br />
make install</p>
<p>把svn添加到环境变量中, 会方便使用<br />
cd ~<br />
vi .bashrc<br />
在文件最后增加PATH=$PATH:$HOME/install/subversion/bin存盘退出</p>
<p>参考:<br />
<a href="http://www.2maomao.com/blog/bluehost-svn-64/" target="_blank">在Bluehost 64位主机上安装SVN</a><br />
<a href="http://www.bluehostforum.com/showthread.php?t=12099&amp;highlight=subversion" target="_blank">Setting up Subversion on Bluehost</a><br />
<a href="http://hi.baidu.com/iiiii/blog/item/a5720df39f3850cb0b46e00b.html" target="_blank">Linux/Ubuntu 下编译安装 Subversion-1.4.0 (svn) 全攻略!</a><br />
<a href="http://www.sunboyu.cn/2008/07/26/subversion-150-%E7%BC%96%E8%AF%91%E5%8F%82%E6%95%B0.shtml" target="_blank">subversion-1.5.0 编译参数</a><br />
<a href="http://www.bernzilla.com/item.php?id=651" target="_blank">Installing the Subversion Client with SSL Support on Linux</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.iworm.net%2F2008%2F10%2F31%2F%25e5%259c%25a8bluehost%25e4%25b8%258a%25e5%25ae%2589%25e8%25a3%2585subversion%2F&amp;title=%E5%9C%A8BlueHost%E4%B8%8A%E5%AE%89%E8%A3%85Subversion" id="wpa2a_18"><img src="http://blog.iworm.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.iworm.net/2008/10/31/%e5%9c%a8bluehost%e4%b8%8a%e5%ae%89%e8%a3%85subversion/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/cn/</creativeCommons:license>
	</item>
		<item>
		<title>封装YUI Table</title>
		<link>http://blog.iworm.net/2007/11/29/%e5%b0%81%e8%a3%85yui-table/</link>
		<comments>http://blog.iworm.net/2007/11/29/%e5%b0%81%e8%a3%85yui-table/#comments</comments>
		<pubDate>Thu, 29 Nov 2007 05:11:53 +0000</pubDate>
		<dc:creator>iworm</dc:creator>
				<category><![CDATA[编程]]></category>

		<guid isPermaLink="false">http://iworm.net/2007/11/29/%e5%b0%81%e8%a3%85yui-table/</guid>
		<description><![CDATA[以前做Research的时候用C#把YUI的Table封装了起来. 这里是代码, 仅供参考.]]></description>
			<content:encoded><![CDATA[<p>以前做Research的时候用C#把YUI的Table封装了起来.</p>
<p><a href="http://www.box.net/shared/66dulgtn7n">这里是代码</a>, 仅供参考.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.iworm.net%2F2007%2F11%2F29%2F%25e5%25b0%2581%25e8%25a3%2585yui-table%2F&amp;title=%E5%B0%81%E8%A3%85YUI%20Table" id="wpa2a_20"><img src="http://blog.iworm.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.iworm.net/2007/11/29/%e5%b0%81%e8%a3%85yui-table/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/cn/</creativeCommons:license>
	</item>
	</channel>
</rss>

