﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-天空是蓝色的-随笔分类-PHP</title><link>http://www.blogjava.net/bluesky/category/6410.html</link><description>做好软件为中国
#gcc -c helloworld.c -o helloworld.o //编译目标文件
#gcc helloworld.o -o helloworld //编译成可执行exe
#helloworld //运行exe</description><language>zh-cn</language><lastBuildDate>Sun, 06 May 2007 14:19:57 GMT</lastBuildDate><pubDate>Sun, 06 May 2007 14:19:57 GMT</pubDate><ttl>60</ttl><item><title>CheckBox选中所有的项[JavaScript]</title><link>http://www.blogjava.net/bluesky/archive/2006/06/23/54751.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Fri, 23 Jun 2006 09:51:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2006/06/23/54751.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/54751.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2006/06/23/54751.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/54751.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/54751.html</trackback:ping><description><![CDATA[
		<p>&lt;html&gt;<br />&lt;head&gt;<br />&lt;title&gt;<br />&lt;/title&gt;<br />&lt;body&gt;<br />&lt;form name="Form1"&gt;</p>
		<p>&lt;input name="allbox" type="checkbox" onClick="TA();" title="选中或清除选中所有的项目" tabindex="105"&gt;选中或清除选中所有的项目</p>
		<p>&lt;br/&gt;<br />&lt;span class="X"&gt;<br />&lt;input type="checkbox" name="ABC" class="A" onClick="TTA(this);"&gt;清明时节&lt;/span&gt;<br />&lt;br/&gt;<br />&lt;span class="X"&gt;<br />&lt;input type="checkbox" name="DEF" class="A" onClick="TTA(this);"&gt;长江水啊&lt;/span&gt;<br />&lt;br/&gt;<br />&lt;span class="X"&gt;<br />&lt;input type="checkbox" name="GHL" class="A" onClick="TTA(this);"&gt;嘿嘿测试&lt;/span&gt;<br />&lt;br/&gt;<br />&lt;/form&gt;</p>
		<p>&lt;script language="javascript"&gt;<br />var frm = document.Form1;<br />&lt;/script&gt;</p>
		<p>
				<br />&lt;script language="JavaScript"&gt;</p>
		<p>function TA(isO,noHL){<br /> var trk = 0;<br /> <br /> <br /> for(var i=0;i&lt;frm.elements.length;i++){<br />  var e=frm.elements[i];</p>
		<p>  if((e.name !='allbox') &amp;&amp; (e.type == 'checkbox')){<br />    e.checked = frm.allbox.checked;<br />   if (frm.allbox.checked){<br />    //e.parentElement.className = "H"; //.parentElement不兼容firefox浏览器 <br />    e.parentNode.className = "H";//调用设置父节点元素class改变背景色<br />   <br />   }else{<br />    e.parentNode.className = "X";//调用设置父节点元素class改变背景色<br />   }<br />  }<br /> }<br />}</p>
		<p>function TTA(CB,noHL){<br /> if (CB.checked){<br />  CB.parentNode.className = "H";<br /> }else{<br />  CB.parentNode.className = "X";<br /> }</p>
		<p> </p>
		<p> var TB=TO=0;<br /> for (var i=0;i&lt;frm.elements.length;i++){<br />  var e=frm.elements[i];<br />  if ((e.name != 'allbox') &amp;&amp; (e.type=='checkbox')){<br />   TB++;<br />  if (e.checked)<br />   TO++;<br />  }<br /> }<br /> frm.allbox.checked=(TO==TB)?true:false;<br /> //如果不是所有项被选中则allbox设定未被选中<br />}</p>
		<p>
				<br />&lt;/script&gt;</p>
		<p>&lt;style&gt;<br />.H{<br /> background: #ADD8E6<br />}<br />.X{<br /> background: #FFFFFF<br />}</p>
		<p>&lt;/style&gt;</p>
		<p>
				<br />&lt;/body&gt;&lt;/html&gt;</p>
<img src ="http://www.blogjava.net/bluesky/aggbug/54751.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2006-06-23 17:51 <a href="http://www.blogjava.net/bluesky/archive/2006/06/23/54751.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>记一段代码[PHP]迭代读取数据库</title><link>http://www.blogjava.net/bluesky/archive/2006/06/23/54594.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Thu, 22 Jun 2006 16:09:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2006/06/23/54594.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/54594.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2006/06/23/54594.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/54594.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/54594.html</trackback:ping><description><![CDATA[
		<p>
				<br />&lt;style&gt;</p>
		<p>input, select {<br /> font-size: 14px; <br /> color: #333333; <br /> padding-left:3px; <br /> background:#f6f6f6; <br /> border: #CCCCCC 1px solid;}<br />&lt;/style&gt;<br />&lt;?php<br />require_once dirname(__FILE__) ."/headers.php";</p>
		<p>$i = 0;<br />  </p>
		<p>function category($category_parent_timestamp){<br />   global $db;<br />   global $i;<br />   $result = $db-&gt;get("{category_parent_timestamp} == " . $category_parent_timestamp,null,"categories",false,"category_time","desc"); <br />   sort($result);<br />  <br />   for($index=0;$index&lt;count($result);$index++){          <br />     echo "&lt;option&gt;";<br />     for($x=0;$x&lt;$i;$x++){<br />       echo "--";<br />      }      <br />     echo $result[$index]['category_title'];<br />     echo "&amp;nbsp;";  <br />     $sub = $db-&gt;get("{category_parent_timestamp} == " .$result[$index]['category_timestamp'],null,"categories",false,"category_time","desc"); <br />     if(count($sub)!=0){<br />       $i++;<br />       category($result[$index]['category_timestamp']);//迭代      <br />       $i--;<br />     }<br />     echo "&lt;/option&gt;";<br />   }<br />   <br />}    <br /> <br />echo "&lt;select&gt;";<br />category("0"); <br />echo"&lt;/select&gt;";<br />?&gt;</p>
<img src ="http://www.blogjava.net/bluesky/aggbug/54594.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2006-06-23 00:09 <a href="http://www.blogjava.net/bluesky/archive/2006/06/23/54594.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]PHP开发框架总结</title><link>http://www.blogjava.net/bluesky/archive/2006/04/18/41654.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Tue, 18 Apr 2006 07:11:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2006/04/18/41654.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/41654.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2006/04/18/41654.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/41654.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/41654.html</trackback:ping><description><![CDATA[<a href="http://blog.liu21st.com/index.php?job=art&amp;articleid=a_20050111_231555">http://blog.liu21st.com/index.php?job=art&amp;articleid=a_20050111_231555</a><br /><br />相信每个PHP开发人员都见过很多的PHP开发框架，如<a href="http://blog.liu21st.com/index.php?job=art&amp;articleid=a_20051220_110612" target="_blank">Symfony</a>、Blueshoes和最近比较火的<a href="http://cakephp.org/" target="_blank">Cake</a>等，本站也曾经介绍过不少这样的<a href="http://blog.liu21st.com/index.php?job=art&amp;articleid=a_20050111_231555" target="_blank">开发框架</a><br /><br /><br /><span id="zoom">收集整理了一些主要的PHP开发框架和CMS系统平台，在此一并作个总结，或许以后会有补充。<br /><br /><span style="COLOR: orangered"><strong>开发框架</strong></span><br /><strong>WACT</strong> <a href="http://wact.sourceforge.net/" target="_blank">http://wact.sourceforge.net/</a><br />老牌的PHP编程框架，实现了很多企业级的开发模式<br /><br /><strong>Horde</strong> <a href="http://www.horde.org/horde/" target="_blank">http://www.horde.org/horde/</a><br />提供了一些常用类库，可以满足参数处理、数据压缩、浏览器检测、链接跟踪以及 MIME。需要PEAR类库的支持，提供了API参考。<br /><br /><strong>Seagull </strong><a href="http://seagull.phpkitchen.com/" target="_blank">http://seagull.phpkitchen.com/</a> <strong><span style="COLOR: orangered">推荐</span></strong><br />一个面向对象的PHP开发框架，使用了Pear类库，其主要特性有：运用组件方式、简化数据访问、错误处理机制和权限认证管理等。<br /><br /><strong>studs</strong> <a href="http://mojavelinux.com/projects/studs/" target="_blank">http://mojavelinux.com/projects/studs/</a> &nbsp;<strong><span style="COLOR: orangered">推荐</span></strong><br />Jakarta Struts结构移植过来的PHP开发框架，使用面向对象的开发结构和API，模拟了一个HTTP Servlet容器<br />和使用了PHP服务页面引擎技术<br /><br /><strong>InterJinn</strong> <a href="http://www.interjinn.com/" target="_blank">http://www.interjinn.com/</a><br />有很多扩展模块提供下载，可惜配置文件使用的是inc格式<br /><br /><strong>Php.MVC</strong> <a href="http://www.phpmvc.net/" target="_blank">http://www.phpmvc.net/</a><br />知名的PHP开发框架 ，基于Java的Struts<br /><br /><strong>Phrame</strong> <a href="http://phrame.sourceforge.net/" target="_blank">http://phrame.sourceforge.net/</a><br />虽然不大，但用的很多，也是基于Struts思想<br /><br /><strong>Ambivalence</strong> <a href="http://amb.sourceforge.net/" target="_blank">http://amb.sourceforge.net/</a><br />基于Maverick思想实现的PHP开发框架<br /><br /><strong>binarycloud</strong> <a href="http://www.binarycloud.com/" target="_blank">http://www.binarycloud.com/</a><br />使用了Smarty模板引擎，文档很完善<br /><br /><strong>Prado</strong> <a href="http://www.xisc.com/" target="_blank">http://www.xisc.com/</a><br />Zend获奖作品，基于事件驱动的PHP开发框架<br /><br /><strong>rwfphp</strong> <a href="http://www.rwfphp.org/" target="_blank">http://www.rwfphp.org/</a><br />面向对象和事件驱动的php开发框架<br /><br /><strong>Krysalis</strong> <a href="http://www.kompletecms.com/" target="_blank">http://www.kompletecms.com/</a> <br />把XML文档转换为XHTML文档的PHP系统<br /><br /><strong>FastFrame</strong> &nbsp;<a href="http://codejanitor.com/wp/apps/fastframe/" target="_blank">http://codejanitor.com/wp/apps/fastframe/</a><br />可以快速地实现表单提交<br /><br /><strong>Blueshoes</strong> <a href="http://www.blueshoes.net/" target="_blank">http://www.blueshoes.net/</a> <strong><span style="COLOR: orangered">推荐</span></strong><br />比较先进的一个framework，提供了很多GUI组件<br /><br />下面这些我也没有详细看<br /><strong>Cgiapp</strong> <a href="http://weierophinney.net/matthew/download" target="_blank">http://weierophinney.net/matthew/download</a><br /><strong>Fuselogic</strong> &nbsp;<a href="http://www.haltebis.com/index/wakka/main/FuseLogic" target="_blank">http://www.haltebis.com/index/wakka/main/FuseLogic</a><br /><strong>Copix</strong> <a href="http://copix.aston.fr/" target="_blank">http://copix.aston.fr/</a><br /><strong>logicreate</strong> <a href="http://www.logicreate.com/" target="_blank">http://www.logicreate.com/</a><br /><strong>booby </strong><a href="http://www.nauta.be/booby/" target="_blank">http://www.nauta.be/booby/</a> <br /><br /><strong><span style="COLOR: orangered">主要的CMS系统</span></strong><br /><strong>Drupal </strong><a href="http://www.drupal.org/" target="_blank">http://www.drupal.org/</a><br /><strong>Mambo</strong> <a href="http://www.mamboportal.com/" target="_blank">http://www.mamboportal.com/</a><br /><strong>Nucleus </strong><a href="http://nucleuscms.org/" target="_blank">http://nucleuscms.org/</a><br /><strong>Midgard</strong> <a href="http://www.midgard-project.org/" target="_blank">http://www.midgard-project.org/</a><br /><strong>Pmachine</strong> <a href="http://www.pmachine.com/" target="_blank">http://www.pmachine.com/</a><br /><strong>PostNuke</strong> <a href="http:///" target="_blank">http://www.post-nuke.net/</a><br /><strong>sitellite</strong> <a href="http://www.sitellite.org/" target="_blank">http://www.sitellite.org/ </a><br /><strong>eZPublish</strong> <a href="http://ez.no/" target="_blank">http://ez.no/</a><br /><strong>limb </strong><a href="http://limb-project.com/" target="_blank">http://limb-project.com/</a><br />PS：众多的Blog系统就不再这个范畴之内了，不再列出</span><img src ="http://www.blogjava.net/bluesky/aggbug/41654.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2006-04-18 15:11 <a href="http://www.blogjava.net/bluesky/archive/2006/04/18/41654.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP文本数据库引擎 </title><link>http://www.blogjava.net/bluesky/archive/2006/04/13/40827.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Thu, 13 Apr 2006 02:58:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2006/04/13/40827.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/40827.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2006/04/13/40827.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/40827.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/40827.html</trackback:ping><description><![CDATA[<a href="http://www.zengrong.net/25/">http://www.zengrong.net/25/</a><br /><br />
<p><a href="http://chibiguy.dotgeek.org/" target="_blank">txtSQL</a></p>
<ul>
    <li><a href="http://txtsql.sourceforge.net/content/demos/txtSQLAdmin/index.php" target="_blank">txtSQLAdmin</a> </li>
    <li><a href="http://chibiguy.dotgeek.org/docs/index.php" target="_blank">帮助文档</a> </li>
    <li><a href="http://chibiguy.dotgeek.org/pages/benchmarks.php?section=3" target="_blank">测试报告</a> </li>
</ul>
<ol>
    <li>速度快（有四个主要的文本数据库速度比较） </li>
    <li>基本上模拟了SQL的所有语法 </li>
    <li>强大的错误处理 </li>
    <li>完善的帮助文档 </li>
    <li>免费使用 </li>
</ol>
<p><a href="http://www.3ants.org/txtdb/" target="_blank">txtdb</a></p>
<p>国人开发的一个小型文本数据库系统。</p>
<p><a href="http://www.myupb.com/ourscripts_textdb.php" target="_blank">Myupb的TextDB</a></p>
<p><a href="http://www.c-worker.ch/txtdbapi/" target="_blank">txt db api</a></p>
<p><a href="http://sourceforge.net/projects/fsql/" target="_blank">Flat-File SQL</a></p>
<p><a href="http://textdb.sourceforge.net/" target="_blank">TextDB</a> </p><img src ="http://www.blogjava.net/bluesky/aggbug/40827.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2006-04-13 10:58 <a href="http://www.blogjava.net/bluesky/archive/2006/04/13/40827.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WebErp不错~~</title><link>http://www.blogjava.net/bluesky/archive/2006/03/02/33168.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Thu, 02 Mar 2006 04:07:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2006/03/02/33168.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/33168.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2006/03/02/33168.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/33168.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/33168.html</trackback:ping><description><![CDATA[<br /><br /><br /><a href="http://www.weberp.org/">http://www.weberp.org/</a>&nbsp;主页<br /><br /><br /><a href="http://sourceforge.net/project/showfiles.php?group_id=70949">http://sourceforge.net/project/showfiles.php?group_id=70949</a><br /><br />sourceforge下载不了,<br />找到了下边的这个链接<br /><br /><a href="http://www.interdynamics.com.tw/webERP_3.04.zip">http://www.interdynamics.com.tw/webERP_3.04.zip</a><br /><br />第一步,安装数据库<br />create database weberp;<br />把sql\mysql\weberp-demo.sql 插入数据库<br /><br />第二步<br />修改config.php<br />数据库用户名密码<br /><br />第三步<br />修改includes/LanguageSetup.php<br />第27行<br />This maybe reqiured in some stubborn installations(写死的设置)<br /><br />&nbsp;$Locale = setlocale (LC_CTYPE, $_SESSION['Language']);<br />&nbsp;$Locale = setlocale (LC_MESSAGES, $_SESSION['Language']);<br />屏蔽掉<br /><br />$Locale = setlocale (LC_ALL, $_SESSION['Language']);<br />打开<br />修改<br />$Locale = setlocale (LC_ALL, $_SESSION['en_US']);<br /><br /><br /><a href="http://edwardleen.minidns.net/weberp/">http://edwardleen.minidns.net/weberp/</a><br />这是人家汉化的,好像没有开源汉化包包~~<br /><img src ="http://www.blogjava.net/bluesky/aggbug/33168.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2006-03-02 12:07 <a href="http://www.blogjava.net/bluesky/archive/2006/03/02/33168.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转载]创造世界上最简单的 PHP 开发模式</title><link>http://www.blogjava.net/bluesky/archive/2006/01/17/28316.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Tue, 17 Jan 2006 08:43:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2006/01/17/28316.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/28316.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2006/01/17/28316.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/28316.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/28316.html</trackback:ping><description><![CDATA[<P><A href="http://sunswin.blogbus.com/logs/2005/09/1417144.html">http://sunswin.blogbus.com/logs/2005/09/1417144.html</A></P>
<P><A href="http://blog.csdn.net/hahawen/archive/2004/09/13/102557.aspx">http://blog.csdn.net/hahawen/archive/2004/09/13/102557.aspx</A></P>
<P>&nbsp;</P>
<P>/*************************/<BR>/* author:大龄青年<BR>/* email :wenadmin@sina.com<BR>/* from: <A href="http://blog.csdn.net/hahawen">http://blog.csdn.net/hahawen</A><BR>/*************************/</P>
<P>原代码下载: <A href="http://club.phpe.net/index.php?s=&amp;act=Attach&amp;type=post&amp;id=29432">http://club.phpe.net/index.php?s=&amp;act=Attach&amp;type=post&amp;id=29432</A></P>
<P>（近来帮许多网友改程序，发现一个问题，就是大家用php开发设计模式的非常的混乱，所以写下这篇文章，希望对大家都有帮助）</P>
<P>php作为“最简单”的Web脚本语言, 在国内的市场越来越大，phper越来越多，但是感觉大多数人好像没有考虑到模式问题，什么样的设计模式才是最优的，才是最适合自己目前工作的，毕竟效率是最重要的（用省下的时间打游戏，多美啊...）。MVC应该是首选，<A href="http://www.sourceforge.net">www.sourceforge.net</A> 上有好多优秀的基于MVC的开源项目，大家可以冲过去研究研究。</P>
<P>前几天给自己公司网站改版，主要还是文章发布系统，老板说后台我想怎么设计就怎么设计，唯一的前提就是快。于是自己搭建了一个简单的发布系统的框架。如果单纯从文章发布系统上讲，基本上可以满足“中小型”企业网站的文章发布系统的要求，后台的总共的php代码不超过800行，而且支持任意扩充和plugin功能。</P>
<P>废话不再说了，下面把我的架构讲一下，希望对您能有所帮助。</P>
<P>注意：在开始前，需要您下载一个模板处理工具类：“smarttemplate”，并了解一些模板的简单的使用。</P>
<P>我的测试环境：windows2k/apache2/php4.3.2/smarttemplate类库</P>
<P>先讲一下整个web站点的文件的分布，在后面的章节中将陆续创建并填充下面的目录和文件<BR>我的服务器的web的根目录是 “C:/Apache2/htdocs/”<BR>我在下面建立了一个文件夹“cmstest”作为我的网站的主文件夹<BR>文件夹“cmstest”下面的子文件结构是：</P>
<P>/config.inc.php<BR>/list1.php<BR>/list2.php<BR>/new.php<BR>/add.php<BR>/view.php<BR>/page.js<BR>/src/MysqlUtil.php<BR>/src/ArticleUtil.php<BR>/src/CoreUtil.php<BR>/src/ParseTpl.php<BR>/src/lib/smarttemplate/*.* 这个目录用来存放smarttemplate的类库的<BR>/smart/template/list1.htm<BR>/smart/template/list2.htm<BR>/smart/template/new.htm<BR>/smart/template/add.htm<BR>/smart/template/view.htm<BR>/smart/cache/<BR>/smart/temp/</P>
<P><BR>设计步骤：<BR>1、考虑自己公司的网站的特点和已经设计的模板的结构，总结要实现的功能，列出清单。</P>
<P>2、分析功能清单，把功能分类。每一类的功能都是有共同点的，可以通过相同的方法实现的。</P>
<P>3、根据功能，设计数据库的表结构</P>
<P>4、设计一个配置文件config.inc.php, 用来记录网站的一些基本的信息,包括数据库名........</P>
<P>5、为每一类功能设计数据库查询的接口函数，这样以后相似的操作只要调用这个接口就可以了。这样避免了以后可能发生的大量的代码重复的操作，也就达到了代码复用的目的。</P>
<P>6、定义自己对模板工具的包装函数，以后调用的时候就不用管模板工具的使用问题了，只有往自己的包装函数里面塞数就可以了。</P>
<P>7、基础函数已经ok了，开始轻松的页面实现和模板的处理了。</P>
<P><BR>我们现在就开始设计一个简单的系统，看看我是怎么一步一步地实现一个“最简单的文章的发布系统”的，当然只是我模拟的一个简单的项目，实际中一个项目可能比这要复杂的多。</P>
<P><BR>一、分析我的案例：</P>
<P>呵呵，这个客户项目好简单的啊，幸福ing..........</P>
<P>list1.php：有三个文章列表和一个按钮，“php开发文章列表”“php开发热点文章列表”“asp开发最新文章”“添加新文章”<BR>list2.php：有2个文章列表“asp开发文章列表”“asp开发热点文章列表”<BR>new.php: 一个添加文章的表单的页面<BR>add.php: 处理new.php的表单的页面<BR>view.php: 文章察看的页面</P>
<P>二、分析功能 </P>
<P>“php开发文章列表”“asp开发文章列表”-------按文章的发布顺序，倒序排列显示，每页显示5篇文章<BR>“php开发热点文章列表”“asp开发热点文章列表”-------按文章的点击察看次数排序显示文章，显示3篇文章<BR>“asp开发最新文章”按文章的发布顺序，倒序排列显示，显示3篇文章<BR>“添加新文章”------一个文章的发布功能, 包括文章标题/作者/内容<BR>“文章察看”---------显示某篇文章内容</P>
<P>综合的看一下,对功能进行分类包括:<BR>1、文章列表：正常的分页列表、按点击数列表、按发布顺序的列表<BR>2、文章发布：一个表单的输入和处理<BR>3、文章察看：读取显示文章内容</P>
<P>呵呵，功能的确是太简单了些。</P>
<P>三、设计数据库：</P>
<P>数据库名：cmstest</P>
<P>数据表：</P>
<P>CREATE TABLE `article` (<BR>`id` INT NOT NULL AUTO_INCREMENT,<BR>`title` VARCHAR( 100 ) NOT NULL ,<BR>`content` TEXT NOT NULL ,<BR>`datetime` DATETIME NOT NULL ,<BR>`clicks` INT( 11 ) ,<BR>`pid` TINYINT( 2 ) NOT NULL ,<BR>PRIMARY KEY ( `id` ) <BR>);</P>
<P>CREATE TABLE `cat` (<BR>`cid` TINYINT( 2 ) NOT NULL ,<BR>`cname` VARCHAR( 20 ) NOT NULL ,<BR>PRIMARY KEY ( `cid` ) <BR>);</P>
<P>------------------------------<BR>article表是文章内容表，<BR>----------------------------<BR>`id` 文章编号<BR>`title` 文章标题<BR>`content` 文章内容<BR>`datetime` 发布时间<BR>`clicks` 点击数<BR>`pid` 分类表号<BR>------------------------------<BR>cat表是文章的类别表<BR>----------------------------<BR>`cid` 分类表号<BR>`cname` 分类名称<BR>----------------------------</P>
<P>上面是表的数据库结构，光有了这些还不够，还要有数据<BR>INSERT INTO `cat` VALUES(1, "php开发"),(2, "asp开发");<BR>INSERT INTO `article` VALUES(1, "php开发1", "php开发1内容", "2004-8-1 1:1:1", 0, 1);<BR>INSERT INTO `article` VALUES(2, "php开发2", "php开发2内容", "2004-8-2 1:1:1", 0, 1);<BR>INSERT INTO `article` VALUES(3, "php开发3", "php开发3内容", "2004-8-3 1:1:1", 4, 1);<BR>INSERT INTO `article` VALUES(4, "php开发4", "php开发4内容", "2004-8-4 1:1:1", 3, 1);<BR>INSERT INTO `article` VALUES(5, "php开发5", "php开发5内容", "2004-8-5 1:1:1", 2, 1);<BR>INSERT INTO `article` VALUES(6, "php开发6", "php开发6内容", "2004-8-6 1:1:1", 1, 1);<BR>INSERT INTO `article` VALUES(7, "php开发7", "php开发7内容", "2004-8-7 1:1:1", 0, 1);<BR>INSERT INTO `article` VALUES(8, "jsp开发1", "jsp开发1内容", "2004-8-1 1:1:1", 0, 2);<BR>INSERT INTO `article` VALUES(9, "jsp开发2", "jsp开发2内容", "2004-8-2 1:1:1", 0, 2);<BR>INSERT INTO `article` VALUES(10, "jsp开发3", "jsp开发3内容", "2004-8-3 1:1:1", 4, 2);<BR>INSERT INTO `article` VALUES(11, "jsp开发4", "jsp开发4内容", "2004-8-4 1:1:1", 3, 2);<BR>INSERT INTO `article` VALUES(12, "jsp开发5", "jsp开发5内容", "2004-8-5 1:1:1", 2, 2);<BR>INSERT INTO `article` VALUES(13, "jsp开发6", "jsp开发6内容", "2004-8-6 1:1:1", 1, 2);<BR>INSERT INTO `article` VALUES(14, "jsp开发7", "jsp开发7内容", "2004-8-7 1:1:1", 0, 2);</P>
<P><BR>这样我们的数据库就设计完了。接下来就开始涉及到具体的实现了。</P>
<P>四、设计config.inc.php文件</P>
<P>这个文件用来设置一些web上通用的数据信息和一些参数，其他的具体的实现页面都通过这个页面获取需要的数据，下面是配置的清单</P>
<P><BR>//数据库设置<BR>define('DB_USERNAME', 'root');<BR>define('DB_PASSWORD', '');<BR>define('DB_HOST', 'localhost');<BR>define('DB_NAME', 'cmstest');<BR>define('DB_PCONNECT', true);</P>
<P>// web的基本路经设置<BR>define('CMS_ROOT', 'C:/Apache2/htdocs/cmstest/');<BR>define('CMS_SRCPATH', CMS_ROOT.'src/');</P>
<P>//smarttemplate 模板解析工具的设置<BR>define('SMART_REUSE_CODE', false);<BR>define('SMART_TEMPLATE_DIR', CMS_ROOT.'smart/template/');<BR>define('SMART_TEMP_DIR', CMS_ROOT.'smart/temp/');<BR>define('SMART_CACHE_DIR', CMS_ROOT.'smart/cache/');<BR>define('SMART_CACHE_LIFETIME', 100);<BR>require_once(CMS_SRCPATH.'lib/smarttemplate/class.smarttemplate.php');</P>
<P>//要包含的基础文件,里面都是一些基本的函数<BR>require_once CMS_SRCPATH.'MysqlUtil.php';<BR>require_once CMS_SRCPATH.'ArticleUtil.php';<BR>require_once CMS_SRCPATH.'CoreUtil.php';<BR>require_once CMS_SRCPATH.'ParseTpl.php';</P>
<P>//session 控制<BR>session_cache_limiter('private_no_expire');<BR>session_start();</P>
<P>?&gt;</P>
<P>其中的define('CMS_ROOT', 'C:/Apache2/htdocs/cmstest/');路经根据自己apach的web路经来改（参照最开始介绍文件夹结构的地方改）。</P>
<P><BR>五、制作功能接口（1）</P>
<P>首先对mysql数据库函数进行包装，简化对数据库操作，网上有很多这样的开源的类。但是这里我个人根据自己的需求和习惯，自己对mysql的函数进行了包装，写得好坏就先不管了。这个地方简单的看一下就可以了，不同的包装的类操作是不同的，而且这里的主要目的是理解这套“架构”，不用太扣代码。</P>
<P>-------MysqlUtil.php--------</P>
<P><BR>function dbConnect(){<BR>global $cnn;<BR>$cnn = (DB_PCONNECT? mysql_pconnect(DB_HOST, DB_NAME, DB_PASSWORD):<BR>mysql_connect(DB_HOST, DB_NAME, DB_PASSWORD)) or<BR>die('数据库连接错误');<BR>mysql_select_db(DB_NAME, $cnn) or die('数据库选择错误');<BR>mysql_query("SET AUTOCOMMIT=1");<BR>}</P>
<P>function &amp;dbQuery($sql){<BR>global $cnn;<BR>$rs = &amp;mysql_query($sql, $cnn);<BR>while($item=mysql_fetch_assoc($rs)){<BR>$data[] = $item;<BR>}<BR>return $data;<BR>}</P>
<P>function &amp;dbGetRow($sql){<BR>global $cnn;<BR>$rs = mysql_query($sql) or die('sql语句执行错误');<BR>if(mysql_num_rows($rs)&gt;0)<BR>return mysql_fetch_assoc($rs);<BR>else<BR>return null;<BR>}</P>
<P>function dbGetOne($sql, $fildName){<BR>$rs = dbGetRow($sql);<BR>return sizeof($rs)==null? null: (isset($rs[$fildName])? $rs[$fildName]: null);<BR>}</P>
<P>function &amp;dbPageQuery($sql, $page=1, $pageSize=20){<BR>if($page===null) return dbQuery($sql);<BR>$countSql = preg_replace('|SELECT.*FROM|i','SELECT COUNT(*) count FROM', $sql);<BR>$n = (int)dbGetOne($countSql, 'count');<BR>$data['pageSize'] = (int)$pageSize&lt;1? 20: (int)$pageSize;<BR>$data['recordCount'] = $n;<BR>$data['pageCount'] = ceil($data['recordCount']/$data['pageSize']);<BR>$data['page'] = $data['pageCount']==0? 0: ((int)$page&lt;1? 1: (int)$page);<BR>$data['page'] = $data['page']&gt;$data['pageCount']? $data['pageCount']:$data['page'];<BR>$data['isFirst'] = $data['page']&gt;1? false: true;<BR>$data['isLast'] = $data['page']&lt;$data['pageCount']? false: true;<BR>$data['start'] = ($data['page']==0)? 0: ($data['page']-1)*$data['pageSize']+1;<BR>$data['end'] = ($data['start']+$data['pageSize']-1);<BR>$data['end'] = $data['end']&gt;$data['recordCount']? $data['recordCount']: $data['end'];<BR>$data['sql'] = $sql.' LIMIT '.($data['start']-1).','.$data['pageSize'];<BR>$data['data'] = &amp;dbQuery($data['sql']);<BR>return $data;<BR>}</P>
<P>function dbExecute($sql){<BR>global $cnn;<BR>mysql_query($sql, $cnn) or die('sql语句执行错误');<BR>return mysql_affected_rows($cnn);<BR>}</P>
<P>function dbDisconnect(){<BR>global $cnn;<BR>mysql_close($cnn);<BR>}</P>
<P>function sqlGetOneById($table, $field, $id){<BR>return "SELECT * FROM $table WHERE $field=$id";<BR>}</P>
<P>function sqlMakeInsert($table, $data){<BR>$t1 = $t2 = array();<BR>foreach($data as $key=&gt;$value){<BR>$t1[] = $key;<BR>$t2[] = "'".addslashes($value)."'";<BR>}<BR>return "INSERT INTO $table (".implode(",",$t1).") VALUES(".implode(",",$t2).")";<BR>}</P>
<P>function sqlMakeUpdateById($table, $field, $id, $data){<BR>$t1 = array();<BR>foreach($data as $key=&gt;$value){<BR>$t1[] = "$key='".addslashes($value)."'";<BR>}<BR>return "UPDATE $table SET ".implode(",", $t1)." WHERE $field=$id";<BR>}</P>
<P>function sqlMakeDelById($table, $field, $id){<BR>return "DELETE FROM $table WHERE $field=$id";<BR>}</P>
<P>?&gt;</P>
<P>五、制作功能接口（2）</P>
<P>下面来正式的看看，我们共要实现的功能进行的包装</P>
<P>------------ArticleUtil.php----------------<BR>//显示文章列表的函数<BR>//getArticleList(文章类别, 排序方法, 当前显示第几页, 每页显示几条)<BR>function getArticleList($catId, $order, $page, $pageSize){<BR>$sql = "SELECT * FROM article WHERE pid=$catId ORDER BY $order";<BR>return dbPageQuery($sql, $page, $pageSize);<BR>}<BR>//查询某个文章的内容<BR>//getArticle(文章编号)<BR>function getArticle($id){<BR>$sqlUpdate = "UPDATE article SET clicks=clicks+1 WHERE id=$id";<BR>dbExecute($sqlUpdate);<BR>$sql = "SELECT * FROM article WHERE art_id=$id";<BR>return dbGetRow($sql);<BR>}<BR>//添加文章<BR>//addArticle(文章内容数组)<BR>function addArticle($data){<BR>$sql = sqlMakeInsert('article', $data);<BR>return dbExecute($sql);<BR>}<BR>?&gt;</P>
<P>这段代码是不是就简单多了啊？这就是自己对mysql函数进行包装的好处！<BR>下面来研究一下他们是怎么实现我们的功能的呢。<BR>“php开发文章列表”--------getArticleList(1, "id DESC", $page, 5) <BR>“asp开发文章列表”--------getArticleList(2, "id DESC", $page, 5)<BR>“php开发热点文章列表”----getArticleList(1, "clicks DESC, id DESC", 1, 3)<BR>“asp开发热点文章列表”----getArticleList(2, "clicks DESC, id DESC", 1, 3)<BR>“asp开发最新文章”--------getArticleList(2, "id DESC", 1, 3)<BR>“添加新文章”-------------addArticle($data)<BR>“察看文章”---------------getArticle($id)</P>
<P><BR>六、对smarttemplate类进行包装（革命尚未成功，同志仍须努力）</P>
<P>具体的smarttemplate的使用这里就不讲了，不然口水讲没了，都讲不完。下面这个是具体的对包装函数</P>
<P>-------------ParseTpl.php----------------</P>
<P><BR>function renderTpl($viewFile, $data){<BR>$page = new SmartTemplate($viewFile);<BR>foreach($data as $key=&gt;$value){<BR>if(isset($value[data])){<BR>$page-&gt;assign($key, $value[data]);<BR>unset($value[data]);<BR>$page-&gt;assign($key."_page", $value);<BR>} else {<BR>$page-&gt;assign($key, $value);<BR>}<BR>}<BR>$page-&gt;output();<BR>}</P>
<P>?&gt;</P>
<P>七：文章列表察看页面实现和模板处理（万里长征的最后一步）</P>
<P>先来看看页面list1的实现,在list1里面分页用了一个page.js文件，这个文件是自己给自己写的一个js分页的函数，挺好用的<BR>---------------page.js---------------<BR>//--------共 20 条记录，当前 86/99 页 [1]... [82] [83] [84] [85] [86] [87] [88] [89] [90] ...[99] GO-------------------<BR>//recordCount = 20;<BR>//show = 20<BR>//pageShow = 11;<BR>//pageCount = 100;<BR>//pageNow = 86;<BR>//pageStr = "?page=_page_";<BR>//document.write(showListPage(recordCount, show, pageCount, pageNow, pageStr));<BR>function showListPage(recordCount, show, pageShow, pageCount, pageNow, pageStr){<BR>if(pageCount&lt;1) pageCount =0;<BR>if(pageNow&lt;1) pageNow = 0;<BR>str = '共 '+recordCount+' 条记录，当前 '+pageNow+'/'+pageCount+' 页 ';</P>
<P>if(pageCount&lt;=pageShow){<BR>startHave = false;<BR>endHave = false;<BR>startNum = 1;<BR>endNum = pageCount;<BR>} else if(pageNow-1 &lt;= pageShow/2){<BR>startHave = false;<BR>endHave = true;<BR>startNum = 1;<BR>endNum = pageShow-1;<BR>} else if(pageCount-pageNow &lt;= pageShow/2){<BR>startHave = true;<BR>endHave = false;<BR>startNum = pageCount - pageShow + 2;<BR>endNum = pageCount;<BR>} else {<BR>startHave = true;<BR>endHave = true;<BR>startNum = pageNow - Math.floor((pageShow-2)/2);<BR>endNum = startNum + pageShow - 3;<BR>}</P>
<P>if(startHave){<BR>startStr = " [1]... ";<BR>str += startStr;<BR>}</P>
<P>for(i=startNum; i&lt;=endNum; i++){<BR>if(pageNow==i)<BR>str += "[" + i + "]";<BR>else<BR>str += " [" + i + "] ";<BR>}</P>
<P>if(endHave){<BR>endStr = " ...[" + pageCount + "] ";<BR>str += endStr;<BR>}<BR>return str;<BR>}</P>
<P><BR>--------------list1.htm----------------<BR>添加新文章 </P>
<P><BR>--------------------------------------------------------------------------------</P>
<P><BR>&nbsp;php开发文章 </P>
<P><BR>&nbsp;{id}--{title} </P>
<P><BR>&nbsp;</P>
<P>&nbsp;</P>
<P>&nbsp;</P>
<P>--------------------------------------------------------------------------------</P>
<P><BR>&nbsp;php开发热点文章 </P>
<P><BR>&nbsp;{id}--{title} </P>
<P><BR>&nbsp;<BR>--------------------------------------------------------------------------------</P>
<P><BR>&nbsp;asp开发最新文章 </P>
<P><BR>&nbsp;{id}--{title} </P>
<P><BR>&nbsp;</P>
<P><BR>--------------list1.php----------------</P>
<P><BR>require_once "config.inc.php";</P>
<P>dbConnect();<BR>$data = array();<BR>$data[phplist] = getArticleList(1, "id DESC", (int)$_GET[page], 5);<BR>$data[phphotlist] = getArticleList(1, "clicks DESC, id DESC", 1, 3);<BR>$data[aspnewlist] = getArticleList(2, "id DESC", 1, 3);<BR>dbDisconnect();</P>
<P>renderTpl('list1.htm', $data);</P>
<P>?&gt;</P>
<P>运行的效果怎么样，是不是实现了要求的功能呢。现在我们再做一下改动，在里面加上“asp开发热点文章列表”，实现代码如下</P>
<P>--------------list1.htm----------------<BR>添加新文章 </P>
<P><BR>--------------------------------------------------------------------------------</P>
<P><BR>&nbsp;php开发文章 </P>
<P><BR>&nbsp;{id}--{title} </P>
<P><BR>&nbsp;</P>
<P>&nbsp;</P>
<P>&nbsp;</P>
<P>--------------------------------------------------------------------------------</P>
<P><BR>&nbsp;php开发热点文章 </P>
<P><BR>&nbsp;{id}--{title} </P>
<P><BR>&nbsp;<BR>--------------------------------------------------------------------------------</P>
<P><BR>&nbsp;asp开发最新文章 </P>
<P><BR>&nbsp;{id}--{title} </P>
<P><BR>&nbsp;</P>
<P>&nbsp;asp热点文章 </P>
<P><BR>&nbsp;{id}--{title} </P>
<P><BR>&nbsp;</P>
<P><BR>--------------list1.php----------------</P>
<P><BR>require_once "config.inc.php";</P>
<P>dbConnect();<BR>$data = array();<BR>$data[phplist] = getArticleList(1, "id DESC", (int)$_GET[page], 5);<BR>$data[phphotlist] = getArticleList(1, "clicks DESC, id DESC", 1, 3);<BR>$data[aspnewlist] = getArticleList(2, "id DESC", 1, 3);<BR>$data[asphotlist] = getArticleList(2, "clicks DESC, id DESC", 1, 3);<BR>dbDisconnect();</P>
<P>renderTpl('list1.htm', $data);</P>
<P>?&gt;</P>
<P>仔细观察一下前后的区别，list1.php里面只是简单的加入了一行的代码，就实现这个改动，感觉怎么样啊？是不是超级简单。</P>
<P>其实这种设计模式的好处还不只是这点：<BR>1、可以把程序的核心代码隔离开管理，便于以后程序的管理维护<BR>2、对于程序的可扩展性也很好，假设list1.php中要加入产品列表，我是不是也可以这么做呢？把对产品的管理也写成统一的数据库操作接口，然后简单的修改模板文件加入产品列表部分，最后在list1.php中加入一行函数调用的代码，就可以实现。<BR>3、代码复用，如果您是做中小型企业网站的，那这么做对您的好处是最大的，因为这种类型的网站的设计结构几乎是一样的，您可能只需要更改一下模板的样式，就可以赚到钞票了。</P>
<P>这么看来这种模式是不是给您带来了很多的好处呢？</P>
<P><BR>-----------lsit2.htm---------------<BR>添加新文章 </P>
<P>&nbsp;</P><img src ="http://www.blogjava.net/bluesky/aggbug/28316.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2006-01-17 16:43 <a href="http://www.blogjava.net/bluesky/archive/2006/01/17/28316.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转载]PHP 编码规范</title><link>http://www.blogjava.net/bluesky/archive/2006/01/17/28315.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Tue, 17 Jan 2006 08:34:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2006/01/17/28315.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/28315.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2006/01/17/28315.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/28315.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/28315.html</trackback:ping><description><![CDATA[<DIV class=logsTitle><A href="http://sunswin.blogbus.com/logs/2005/09/1417148.html"><FONT color=#003333>PHP 编码规范</FONT></A></DIV>TAG：<A href="http://sunswin.blogbus.com/s8820/index.html"><FONT color=#003333>web</FONT></A>&nbsp;<A href="http://sunswin.blogbus.com/s6915/index.html"><FONT color=#003333>PHP</FONT></A><BR><BR>
<P class=text>原文：<A href="http://pear.php.net/manual/en/standards.php" target=_blank><FONT color=#000000>http://pear.php.net/manual/en/standards.php</FONT></A><BR><BR>翻译：廖宇雷<BR><BR>最后更新日期：2003/05/06</P>
<P class=text>&nbsp;</P>
<P class=text>内容列表</P>
<UL>
<LI><A href="http://www.openphp.cn/index.php/article/2/165/index.html#indenting"><FONT color=#000000>缩进</FONT></A> 
<LI><A href="http://www.openphp.cn/index.php/article/2/165/index.html#ControlStructures"><FONT color=#000000>控制结构</FONT></A> 
<LI><A href="http://www.openphp.cn/index.php/article/2/165/index.html#FunctionCalls"><FONT color=#000000>函数调用</FONT></A> 
<LI><A href="http://www.openphp.cn/index.php/article/2/165/index.html#FunctionDefinitions"><FONT color=#000000>函数定义</FONT></A> 
<LI><A href="http://www.openphp.cn/index.php/article/2/165/index.html#Comments"><FONT color=#000000>注释</FONT></A> 
<LI><A href="http://www.openphp.cn/index.php/article/2/165/index.html#IncludingCode"><FONT color=#000000>包含代码</FONT></A> 
<LI><A href="http://www.openphp.cn/index.php/article/2/165/index.html#CodeTags"><FONT color=#000000>PHP 代码标记</FONT></A> 
<LI><A href="http://www.openphp.cn/index.php/article/2/165/index.html#HeaderCommentBlocks"><FONT color=#000000>头注释块</FONT></A> 
<LI><A href="http://www.openphp.cn/index.php/article/2/165/index.html#UsingCVS"><FONT color=#000000>使用 CVS</FONT></A> 
<LI><A href="http://www.openphp.cn/index.php/article/2/165/index.html#ExampleURLs"><FONT color=#000000>例子 URLs</FONT></A> 
<LI><A href="http://www.openphp.cn/index.php/article/2/165/index.html#NamingConventions"><FONT color=#000000>命名约定</FONT></A> </LI></UL>
<HR>

<P><A name=indenting></A></P>
<P class=node>缩进</P>
<P class=text>缩进使用4个空格，而不是 tab。如果你使用 Emacs 编辑 PEAR 代码，你应该设置 indent-tabs-mode 为 nil。下面是一个 mode hook 的示例，用于设置 Emacs 符合缩进标准（你必须确保在编辑 PHP 文件时，这些设置发生作用）：</P>
<P class=code><FONT face="Courier New"><SPAN class=code-keyword>&nbsp; (defun</SPAN> php-mode-hook <SPAN class=code-keyword>()</SPAN><BR><SPAN class=code-keyword>&nbsp;&nbsp;(setq</SPAN> tab-width 4<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c-basic-offset 4<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c-hanging-comment-ender-p nil<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;indent-tabs-mode<BR><SPAN class=code-keyword>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(not</SPAN><BR><SPAN class=code-keyword>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(and</SPAN> <SPAN class=code-keyword>(</SPAN>string-match <SPAN class=code-keyword>"/\\(</SPAN>PEAR<SPAN class=code-keyword>\\|</SPAN>pear<SPAN class=code-keyword>\\)/" (</SPAN>buffer-file-name<SPAN class=code-keyword>))</SPAN><BR><SPAN class=code-keyword>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(</SPAN>string-match <SPAN class=code-keyword>"\</SPAN>.php$<SPAN class=code-keyword>" (</SPAN>buffer-file-name<SPAN class=code-keyword>))))))</SPAN></FONT></P>
<P class=text>这里是同等效果的 vim 规则：</P>
<P class=code><FONT face="Courier New"><SPAN class=code-keyword>&nbsp; set</SPAN> expandtab<BR><SPAN class=code-keyword>&nbsp;&nbsp;set</SPAN> shiftwidth<SPAN class=code-keyword>=</SPAN>4<BR><SPAN class=code-keyword>&nbsp;&nbsp;set</SPAN> softtabstop<SPAN class=code-keyword>=</SPAN>4<BR><SPAN class=code-keyword>&nbsp;&nbsp;set</SPAN> tabstop<SPAN class=code-keyword>=</SPAN>4</FONT></P>
<HR>

<P class=text><A name=ControlStructures></A></P>
<P class=node>控制结构</P>
<P class=text>控制结构包含 if、for、while、switch 等。这里有一个 if 语句的示例和一个 switch 语句的示例：</P>
<P class=text>if 语句的示例：</P>
<P class=code><FONT face="Courier New">&lt;?php<BR><SPAN class=code-keyword>if ((</SPAN>condition1<SPAN class=code-keyword>) || (</SPAN>condition2<SPAN class=code-keyword>)) {</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;action1;<BR><SPAN class=code-keyword>} elseif ((</SPAN>condition3<SPAN class=code-keyword>) &amp;&amp; (</SPAN>condition4<SPAN class=code-keyword>)) {</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;action2;<BR><SPAN class=code-keyword>} else {</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;defaultaction;<BR></FONT><FONT face="Courier New"><SPAN class=code-keyword>}<BR></SPAN>?&gt;</FONT></P>
<P class=text>switch 语句的示例：</P>
<P class=code><FONT face="Courier New">&lt;?php<BR><SPAN class=code-keyword>switch (</SPAN>condition<SPAN class=code-keyword>) {</SPAN><BR><SPAN class=code-keyword>case</SPAN> 1<SPAN class=code-keyword>:</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;action1<SPAN class=code-keyword>;</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class=code-keyword>break;</SPAN><BR><SPAN class=code-keyword>case</SPAN> 2<SPAN class=code-keyword>:</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;action2<SPAN class=code-keyword>;</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class=code-keyword>break;</SPAN><BR><SPAN class=code-keyword>default:</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;defaultaction<SPAN class=code-keyword>;</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class=code-keyword>break;</SPAN><BR><SPAN class=code-keyword>}</SPAN><BR>?&gt;</FONT></P>
<P class=text>控制语句应该在控制关键词和开始的圆括号之间应该有一个空格，以此和函数调用进行区别。</P>
<P class=text>强烈建议你总是使用花括号将控制结构各部分标识出来。即使是在技术上可以不使用花括号的地方。这可以增加代码的可读性，同时避免在结构部分增加新行后引入逻辑上的错误。</P>
<P class=text>原始代码：</P>
<P class=code><FONT face="Courier New"><SPAN class=code-keyword>if (</SPAN>condition<SPAN class=code-keyword>)</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class=code-keyword>return </SPAN>true<SPAN class=code-keyword>;</SPAN><BR></FONT><FONT face="Courier New"><SPAN class=code-keyword>else<BR>&nbsp;&nbsp;&nbsp;&nbsp;return </SPAN>false<SPAN class=code-keyword>;</SPAN></FONT></P>
<P class=text>修改后的代码：</P>
<P class=code><FONT face="Courier New"><SPAN class=code-keyword>if (</SPAN>condition<SPAN class=code-keyword>)</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;do something<SPAN class=code-keyword>;</SPAN> <SPAN class=code-comment>// 出现逻辑错误</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class=code-keyword>return </SPAN>true<SPAN class=code-keyword>;</SPAN><BR></FONT><FONT face="Courier New"><SPAN class=code-keyword>else<BR>&nbsp;&nbsp;&nbsp;&nbsp;return </SPAN>false<SPAN class=code-keyword>;</SPAN></FONT></P>
<P class=text>正确的做法：</P>
<P class=code><FONT face="Courier New"><SPAN class=code-keyword>if (</SPAN>condition<SPAN class=code-keyword>) {</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;do something<SPAN class=code-keyword>;</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class=code-keyword>return </SPAN>true<SPAN class=code-keyword>;</SPAN><BR></FONT><FONT face="Courier New"><SPAN class=code-keyword>} else {<BR>&nbsp;&nbsp;&nbsp;&nbsp;return </SPAN>false</FONT><SPAN class=code-keyword><FONT face="Courier New">;<BR>}</FONT></SPAN></P>
<HR>

<P><A name=FunctionCalls></A></P>
<P class=node>函数调用</P>
<P class=text>调用函数时，函数名和开始的括号之间不应该有空白字符。参数和开始及结束的括号之间不应有空格。而除第一个参数外，其他参数都应该用一个空格分隔。这里有一个示例：</P>
<P class=code><FONT face="Courier New">&lt;?php<BR>$var <SPAN class=code-keyword>=</SPAN> foo<SPAN class=code-keyword>(</SPAN>$bar<SPAN class=code-keyword>,</SPAN> $baz<SPAN class=code-keyword>,</SPAN> $quux<SPAN class=code-keyword>);</SPAN><BR>?&gt;</FONT></P>
<P class=text>像上面的示例代码，赋值运算等号两边都应该使用一个空格。如果是相关的赋值运算，应该采用下面的形式以提供更好的可读性：</P>
<P class=code><FONT face="Courier New">&lt;?php<BR>$short <SPAN class=code-keyword>=</SPAN> foo<SPAN class=code-keyword>(</SPAN>$bar<SPAN class=code-keyword>);</SPAN><BR>$long_variable <SPAN class=code-keyword>=</SPAN> foo<SPAN class=code-keyword>(</SPAN>$baz<SPAN class=code-keyword>);</SPAN><BR>?&gt;</FONT></P>
<HR>

<P><A name=FunctionDefinitions></A></P>
<P class=node>函数定义</P>
<P class=text>按照“one true brace”约定声明函数：</P>
<P class=code><FONT face="Courier New">&lt;?php<BR><SPAN class=code-keyword>function</SPAN> fooFunction<SPAN class=code-keyword>(</SPAN>$arg1<SPAN class=code-keyword>,</SPAN> $arg2 <SPAN class=code-keyword>=</SPAN> <SPAN class=code-string>''</SPAN><SPAN class=code-keyword>)</SPAN><BR><SPAN class=code-keyword>{</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class=code-keyword>if (</SPAN>condition<SPAN class=code-keyword>) {</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statement<SPAN class=code-keyword>;</SPAN><BR></FONT><FONT face="Courier New"><SPAN class=code-keyword>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;return</SPAN> $val<SPAN class=code-keyword>;</SPAN><BR><SPAN class=code-keyword>}</SPAN><BR>?&gt;</FONT></P>
<P class=text>“one true brace”约定就是开始的花括号单独占一行，而不是跟在其他语句后面。</P>
<P class=text>具有默认值的参数应该位于参数列表的后面（事实上 PHP 语言定义也要求如此）。如果适合，函数应该总是返回一个有意义的值。这里有一个稍微长一点的示例：</P>
<P class=code><FONT face="Courier New">&lt;?php<BR><SPAN class=code-keyword>function</SPAN> connect<SPAN class=code-keyword>(</SPAN>&amp;$dsn<SPAN class=code-keyword>,</SPAN> $persistent <SPAN class=code-keyword>=</SPAN> false<SPAN class=code-keyword>)</SPAN><BR><SPAN class=code-keyword>{</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class=code-keyword>if</SPAN> <SPAN class=code-keyword>(</SPAN>is_array<SPAN class=code-keyword>(</SPAN>$dsn<SPAN class=code-keyword>)) {</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$dsninfo <SPAN class=code-keyword>=</SPAN> <SPAN class=code-keyword>&amp;</SPAN>$dsn<SPAN class=code-keyword>;</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class=code-keyword>} else {</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$dsninfo <SPAN class=code-keyword>=</SPAN> DB<SPAN class=code-keyword>::</SPAN>parseDSN<SPAN class=code-keyword>(</SPAN>$dsn<SPAN class=code-keyword>);</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class=code-keyword>}</SPAN><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class=code-keyword>if (!</SPAN>$dsninfo <SPAN class=code-keyword>|| !</SPAN>$dsninfo<SPAN class=code-keyword>[</SPAN><SPAN class=code-string>'phptype'</SPAN><SPAN class=code-keyword>]) {</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class=code-keyword>return</SPAN> $this<SPAN class=code-keyword>-&gt;</SPAN>raiseError<SPAN class=code-keyword>();</SPAN><BR></FONT><FONT face="Courier New"><SPAN class=code-keyword>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;return </SPAN>true</FONT><FONT face="Courier New"><SPAN class=code-keyword>;<BR>}<BR></SPAN>?&gt;</FONT></P>
<HR>

<P><A name=Comments></A></P>
<P class=node>注释</P>
<P class=text>类型（class）的联机文档应该符合 PHPDoc（类似于 JavaDoc）的约定。更多关于 PHPDoc 的信息可以访问 <A href="http://www.phpdoc.de/" target=_blank><FONT color=#000000>http://www.phpdoc.de/</FONT></A> 获得。</P>
<P class=text>此外，强烈鼓励使用非文档注释。一般性规则是对于那些容易忘记作用的代码添加简短的介绍性注释。</P>
<P class=text>推荐使用 C 样式的注释（/* */）和标准 C++ 注释（//)，而不应该使用 Perl/shell 样式的注释（#）。</P>
<HR>

<P><A name=IncludingCode></A></P>
<P class=node>包含代码</P>
<P class=text>无论在什么地方无条件包含一个类型文件，应该使用 <SPAN class=input>require_once()</SPAN>。如果有条件的包含一个类型文件（例如使用工厂方法），应该使用 <SPAN class=input>include_once()</SPAN>。使用两者中的任何一个都能够确保类型文件只包含一次。它们共享一个文件列表，因此你不需要担心混淆他们 —— 一个文件使用 <SPAN class=input>require_once()</SPAN> 包含后不会在 <SPAN class=input>include_once()</SPAN> 中再一次被包含。</P>
<P class=text>备注：<SPAN class=input>include_once()</SPAN> 和 <SPAN class=input>require_once()</SPAN> 是一个声明，而不是函数。你不需要使用圆括号将文件名扩起来（不过使用括号也不会出现错误）。</P>
<HR>

<P><A name=CodeTags></A></P>
<P class=node>PHP 代码标记</P>
<P class=text>总是使用 &lt;?php ?&gt; 来界定 PHP 代码，而不要使用 &lt;? ?&gt; 速记方式。这是为了符合 PEAR 一致性所必须的，同时也是在不同操作系统和不同安装设置环境下移植 PHP 代码所要求的。</P>
<HR>

<P><A name=HeaderCommentBlocks></A></P>
<P class=node>头注释块</P>
<P class=text>PEAR 发布的所有源代码文件头部都应该包含下面的注释块：</P>
<P class=code><FONT face="Courier New">&lt;?php<BR></FONT><FONT face="Courier New"><SPAN class=code-comment>/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */<BR>// +----------------------------------------------------------------------+<BR>// | PHP version 4 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<BR>// +----------------------------------------------------------------------+<BR>// | Copyright (c) 1997-2002 The PHP Group &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<BR>// +----------------------------------------------------------------------+<BR>// | This source file is subject to version 2.0 of the PHP license, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<BR>// | that is bundled with this package in the file LICENSE, and is &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<BR>// | available at through the world-wide-web at &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<BR>// | http://www.php.net/license/2_02.txt. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<BR>// | If you did not receive a copy of the PHP license and are unable to &nbsp;&nbsp;|<BR>// | obtain it through the world-wide-web, please send a note to &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<BR>// | license@php.net so we can mail you a copy immediately. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<BR>// +----------------------------------------------------------------------+<BR>// | Authors: Original Author &lt;author@example.com&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;|<BR>// | Your Name &lt;you@example.com&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<BR>// +----------------------------------------------------------------------+<BR>//<BR>// $ Id $</SPAN><BR>?&gt;</FONT></P>
<P class=text>这里没有硬性规定要将一个代码贡献者的名字添加到文件注释的作者列表中。一般情况下，他们的更改属于“substantial”目录（意味大约10%到20%的代码被改写）。有一个例外就是代码贡献者重写了函数或者贡献了新的程序逻辑。</P>
<P class=text>简单的代码重组和 bug 修复不应该增加新作者，这是不恰当的。</P>
<P class=text>不在核心 PEAR 仓库中的文件应该有一个类似的注释块来说明版权、许可协议和作者。所有文件应该包含一个模式行（modeline，用于 vim 和 emacs）以确保一致性。</P>
<HR>

<P><A name=UsingCVS></A></P>
<P class=node>使用 CVS</P>
<P class=text>这个小节的内容仅仅适用于 cvs.php.net 上使用 CVS 的包。</P>
<P class=text>在每一个文件中包含 $Id $（两个 $ 符号之间的关键字不能够有空格，但由于此文档也是用 CVS 管理，因此只好加个空格，避免被 CVS 替换掉） CVS 关键字，以便查看文件当前状态和最后修改时间等信息。如果已经存在“Last Modified:”这样的信息，则替换为 $Id $ 标记。</P>
<P class=text>这个小节的其他内容假定你有关于 CVS 标记和分支（branches）的基本知识。</P>
<P class=text>CVS 标记用于标识你包中的文件释放之前所作的修订。下面的列表是必需使用和建议使用的 CVS 标记：</P>
<P class=text><SPAN class=input><FONT face="Courier New">RELEASE_n_n</FONT></SPAN></P>
<BLOCKQUOTE>
<P class=text>（必需的）用于标记一个释放版本。如果你没有使用这个标记，别人就没有办法在你发布一个释放版本时从 CVS 服务器获取你的包。</P></BLOCKQUOTE>
<P class=text><SPAN class=input><FONT face="Courier New">QA_n_n</FONT></SPAN></P>
<BLOCKQUOTE>
<P class=text>（分支，可选）如果你觉得在发布释放版本之前要提供一个候选释放版本，那么一个好主意就是增加一个分支。这个分支可以让你将释放版本隔离出来，并在正式发布释放版本之前可以为这些分支单独应用更新。期间，正常的开发工作可以在主干上继续进行。</P></BLOCKQUOTE>
<P class=text><SPAN class=input><FONT face="Courier New">MAINT_n_n</FONT></SPAN></P>
<BLOCKQUOTE>
<P class=text>（分支，可选）如果你需要创建一个较小修改的释放版本（例如在 1.2 之后发布 1.2.1）。那么你可以创建一个分支来达到目的。</P></BLOCKQUOTE>
<P class=text>仅有 RELEASE 标记是必须的，其他标记为了方便推荐你使用。</P>
<P class=text>下面是一个如何为 "Money_Fast" 包 1.2 释放版本增加标记的示例：</P>
<P class=code><FONT face="Courier New"><SPAN class=text>$</SPAN> <SPAN class=input>cd pear/Money_Fast</SPAN><BR><SPAN class=text>$</SPAN> <SPAN class=input>cvs tag RELEASE_1_2</SPAN><BR></FONT><SPAN class=text><FONT face="Courier New">T Fast.php<BR>T README<BR>T package.xml</FONT></SPAN></P>
<P class=text>经过上面的操作，就可以在 PEAR Web 网站上获取你的一系列释放版本了。</P>
<P class=text>这里是一个如何建立 QA 分支的示例：</P>
<P class=code><FONT face="Courier New"><SPAN class=text>$</SPAN> <SPAN class=input>cvs tag QA_2_0_BP</SPAN><BR><SPAN class=text>...</SPAN><BR><SPAN class=text>$</SPAN> <SPAN class=input>cvs rtag -b -r QA_2_0_BP QA_2_0</SPAN><BR><SPAN class=text>$</SPAN> <SPAN class=input>cvs update -r QA_2_0</SPAN><BR><SPAN class=text>$</SPAN> <SPAN class=input>cvs tag RELEASE_2_0RC1</SPAN><BR><SPAN class=text>...and then the actual release, from the same branch:</SPAN><BR><SPAN class=text>$</SPAN> <SPAN class=input>cvs tag RELEASE_2_0</SPAN></FONT></P>
<P class=text>"QA_2_0_BP" 标记是一个 "branch point" 标记，用于标记分支的开始。总是用这样的标记来标明分支的开始是一个好主意。MAINT 分支可以使用 RELEASE 标记作为它的分支起点。</P>
<HR>

<P><A name=ExampleURLs></A></P>
<P class=node>示例中的 URL</P>
<P class=text>所有示例中用到的 URL 地址都应该是 "example.com"、"example.org"、"example.net"。</P>
<HR>

<P><A name=NamingConventions></A></P>
<P class=node>命名约定</P>
<P class=text>一般而言，class、函数和变量的名字应该总是能够描述让代码阅读者能够容易的知道这些代码的作用。</P>
<P class=input><FONT face="Courier New">Classes</FONT></P>
<P class=text>class 应该具有一个描述性的名字。可能时应该避免使用缩写。class 名字应该总是用一个大写字母开始。从 class 名字中也能够反映出 PEAR class 的层次。层次中的每个级别都用下划线进行分隔。好的 class 名字示例如下：</P>
<P class=code><FONT face="Courier New">Log<BR>Net_Finger<BR>HTML_Upload_Error</FONT></P>
<P class=input>函数和方法</P>
<P class=text>函数和方法应该使用 "studly caps" 样式命名。函数应该将所在包的名字作为前缀，以避免与其他包的函数发生名字冲突。名字的受字母（前缀之后）应该是小写，每一个新单词应该以大写字母开头。下面是一些示例：</P>
<P class=code><FONT face="Courier New">connect<SPAN class=code-keyword>()</SPAN><BR>getData<SPAN class=code-keyword>()</SPAN><BR>buildSomeWidget<SPAN class=code-keyword>()</SPAN><BR>XML_RPC_serializeData<SPAN class=code-keyword>()</SPAN></FONT></P>
<P class=text>私有 class 成员和属性（意味着 class 成员和属性只应该由同一个 class 中声明的成员使用。不过 PHP 并不支持强制性的私有命名空间）应该用一个下划线开头。示例：</P>
<P class=code><FONT face="Courier New">_sort<SPAN class=code-keyword>()</SPAN><BR>_initTree<SPAN class=code-keyword>()</SPAN><BR>$this<SPAN class=code-keyword>-&gt;</SPAN>_status</FONT></P>
<P class=input>常数</P>
<P class=text>常数应该总是全部使用大写字母命名，用下划线来分隔单词。常数名字的前缀应该使用大写的 class/包 名字。例如：DB:: 包使用的所有常数都已 DB_ 开头。</P>
<P class=input>全局变量</P>
<P class=text>如果你的包需要定义全局变量，那么应该用下划线跟上包的名字和另一个下划线作为开头。例如，PEAR 包使用一个全局变量名为 $_PEAR_destructor_object_list。</P>
<P class=input>预定义的值 true、false 和 null</P>
<P class=text>PHP 的内建值 true、false 和 null 必须全部用小写字母书写。</P><img src ="http://www.blogjava.net/bluesky/aggbug/28315.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2006-01-17 16:34 <a href="http://www.blogjava.net/bluesky/archive/2006/01/17/28315.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转载]重新封装的PHPLib DB类</title><link>http://www.blogjava.net/bluesky/archive/2005/12/31/26147.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Sat, 31 Dec 2005 01:40:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2005/12/31/26147.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/26147.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2005/12/31/26147.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/26147.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/26147.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: http://dev.csdn.net/article/81/81559.shtm[&nbsp;&nbsp;连接数据库&nbsp;]//包含数据库处理类文件include_once("database.inc.php");//本地数据库配置define("DB_HOST",&nbsp;&nbsp;&nbsp;&nbsp;"localhost");&nbsp;//数据库服务器define("DB...&nbsp;&nbsp;<a href='http://www.blogjava.net/bluesky/archive/2005/12/31/26147.html'>阅读全文</a><img src ="http://www.blogjava.net/bluesky/aggbug/26147.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2005-12-31 09:40 <a href="http://www.blogjava.net/bluesky/archive/2005/12/31/26147.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转载]几个PHP函数</title><link>http://www.blogjava.net/bluesky/archive/2005/12/30/26067.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Fri, 30 Dec 2005 07:30:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2005/12/30/26067.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/26067.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2005/12/30/26067.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/26067.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/26067.html</trackback:ping><description><![CDATA[<STRONG><FONT color=#006400 size=6>作者主页</FONT></STRONG> <A href="http://phpu.blogchina.com/"><FONT color=#ff1493>http://phpu.blogchina.com/</FONT></A><BR>
<DIV class=diaryContent id=diary468810 style="DISPLAY: block">
<P><FONT style="BACKGROUND-COLOR: #deb887">&nbsp;</P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">获取数字随机数&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV>
<P>之前用过的一些函数，最近会陆续做些整理。</FONT></P>
<P><SPAN><FONT style="BACKGROUND-COLOR: #deb887">获得最小和最大值之间随机数，位数不足补零<BR></FONT></SPAN></P><BR>
<DIV style="MARGIN-LEFT: 5pt"><FONT style="BACKGROUND-COLOR: #deb887"><SPAN style="COLOR: #999"><FONT size=+0>&nbsp;</FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=+0><SPAN style="COLOR: #ff9900">#-------------------------------------------</SPAN></FONT></SPAN></FONT></DIV>
<DIV style="MARGIN-LEFT: 5pt"><SPAN style="COLOR: #000000"><FONT size=+0><FONT style="BACKGROUND-COLOR: #deb887"><SPAN style="COLOR: #ff9900"><SPAN style="COLOR: #999">&nbsp;</SPAN># 获得最小和最大值之间随机数，位数不足补零<BR><SPAN style="COLOR: #999">&nbsp;</SPAN>#-------------------------------------------<BR><SPAN style="COLOR: #999">&nbsp;</SPAN></SPAN><SPAN style="COLOR: #006600">Function </SPAN><SPAN style="COLOR: #0000cc">getRandNumber </SPAN><SPAN style="COLOR: #006600">(</SPAN><SPAN style="COLOR: #0000cc">$fMin</SPAN><SPAN style="COLOR: #006600">, </SPAN><SPAN style="COLOR: #0000cc">$fMax</SPAN></FONT></FONT><FONT size=+0><FONT style="BACKGROUND-COLOR: #deb887"><SPAN style="COLOR: #006600">) {&nbsp;<BR><SPAN style="COLOR: #999">&nbsp; </SPAN></SPAN><SPAN style="COLOR: #0000cc">srand</SPAN><SPAN style="COLOR: #006600">((double)</SPAN><SPAN style="COLOR: #0000cc">microtime</SPAN><SPAN style="COLOR: #006600">()*</SPAN><SPAN style="COLOR: #0000cc">1000000</SPAN></FONT></FONT><FONT size=+0><FONT style="BACKGROUND-COLOR: #deb887"><SPAN style="COLOR: #006600">);<BR><SPAN style="COLOR: #999">&nbsp; </SPAN></SPAN><SPAN style="COLOR: #0000cc">$fLen </SPAN><SPAN style="COLOR: #006600">= </SPAN><SPAN style="COLOR: #cc0000">"%0"</SPAN><SPAN style="COLOR: #006600">.</SPAN><SPAN style="COLOR: #0000cc">strlen</SPAN><SPAN style="COLOR: #006600">(</SPAN><SPAN style="COLOR: #0000cc">$fMax</SPAN><SPAN style="COLOR: #006600">).</SPAN><SPAN style="COLOR: #cc0000">"d"</SPAN></FONT></FONT><FONT size=+0><FONT style="BACKGROUND-COLOR: #deb887"><SPAN style="COLOR: #006600">;<BR><SPAN style="COLOR: #999">&nbsp; </SPAN>Return </SPAN><SPAN style="COLOR: #0000cc">sprintf</SPAN><SPAN style="COLOR: #006600">(</SPAN><SPAN style="COLOR: #0000cc">$fLen</SPAN><SPAN style="COLOR: #006600">, </SPAN><SPAN style="COLOR: #0000cc">rand</SPAN><SPAN style="COLOR: #006600">(</SPAN><SPAN style="COLOR: #0000cc">$fMin</SPAN><SPAN style="COLOR: #006600">,</SPAN><SPAN style="COLOR: #0000cc">$fMax</SPAN></FONT></FONT><FONT size=+0><FONT style="BACKGROUND-COLOR: #deb887"><SPAN style="COLOR: #006600">));<BR><SPAN style="COLOR: #999">&nbsp;</SPAN>}</SPAN> <BR><BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">判断数字大小</SPAN></DIV></FONT></FONT></SPAN><BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">判断数字的大小是否在某个范围内，如果仅仅是判断是否为数字无需使用。<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;#----------------------------------------------------------&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;#&nbsp;判断数字大小，无大小的判断可以用系统带的&nbsp;is_numeric($str)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;#----------------------------------------------------------<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;Function&nbsp;isNumber&nbsp;($fNum</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$fMin</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$fMax</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">)&nbsp;{&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;if&nbsp;(&nbsp;eregi(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">^[0-9]+$</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$fNum)&nbsp;)&nbsp;{&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;$fMax&nbsp;&amp;&amp;&nbsp;</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;$fMin&nbsp;)&nbsp;{&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;Return&nbsp;True</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;}&nbsp;elseif&nbsp;(&nbsp;</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;$fMin&nbsp;&amp;&amp;&nbsp;$fNum&nbsp;&lt;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;$fMax&nbsp;)&nbsp;{&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;Return&nbsp;True</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;}&nbsp;elseif&nbsp;(&nbsp;</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;$fMax&nbsp;&amp;&amp;&nbsp;$fNum&nbsp;&gt;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;$fMin&nbsp;)&nbsp;{&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;Return&nbsp;True</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;}&nbsp;elseif&nbsp;(&nbsp;$fNum&nbsp;&gt;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;$fMin&nbsp;&amp;&amp;&nbsp;$fNum&nbsp;&lt;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;$fMax&nbsp;)&nbsp;{&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;Return&nbsp;True</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;Return&nbsp;False</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;}&nbsp;else&nbsp;{&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;Return&nbsp;False</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;}&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV><BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;随机生成图像验证码&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>根据以前的验证码生成修改而来，需要GD库的支持<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>特点：<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">&nbsp;安全性较强，随机背景加随机像素点绘制<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">&nbsp;生成四位随机数字（可重定义）<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">3</SPAN><SPAN style="COLOR: #000000">&nbsp;验证码存入session，直接取值即可比较<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">4</SPAN><SPAN style="COLOR: #000000">&nbsp;可以带参数调用。（默认是54×22的png图像）<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t&nbsp;图像格式&nbsp;png&nbsp;gif&nbsp;jpeg&nbsp;等<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w&nbsp;图像宽度<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h&nbsp;图像高度<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>调用方式如下：<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&lt;img&nbsp;src</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">verify.php?t=gif&amp;w=60&amp;h=25</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;border</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;alt</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">&gt;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>代码如下：<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&lt;?PHP<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;#----------------------------------------------<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;#&nbsp;文&nbsp;&nbsp;&nbsp;&nbsp;件:&nbsp;verify.php<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;#&nbsp;功&nbsp;&nbsp;&nbsp;&nbsp;能:&nbsp;认证码显示<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Liu21st</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">liu21st@</SPAN><SPAN style="COLOR: #000000">126</SPAN><SPAN style="COLOR: #000000">.com<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;#&nbsp;最后修改:&nbsp;</SPAN><SPAN style="COLOR: #000000">2004</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">05</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">07</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">10</SPAN><SPAN style="COLOR: #000000">:</SPAN><SPAN style="COLOR: #000000">57</SPAN><SPAN style="COLOR: #000000">:</SPAN><SPAN style="COLOR: #000000">30</SPAN><SPAN style="COLOR: #000000">&nbsp;Liu21st<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;#----------------------------------------------<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;$type</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">($_GET</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">[</SPAN><SPAN style="COLOR: #800000">'t'</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">]</SPAN><SPAN style="COLOR: #000000">)?($_GET</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">[</SPAN><SPAN style="COLOR: #800000">'t'</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">]</SPAN><SPAN style="COLOR: #000000">):'png'</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;$width</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">($_GET</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">[</SPAN><SPAN style="COLOR: #800000">'w'</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">]</SPAN><SPAN style="COLOR: #000000">)?($_GET</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">[</SPAN><SPAN style="COLOR: #800000">'w'</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">]</SPAN><SPAN style="COLOR: #000000">):</SPAN><SPAN style="COLOR: #000000">54</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;$height</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">($_GET</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">[</SPAN><SPAN style="COLOR: #800000">'h'</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">]</SPAN><SPAN style="COLOR: #000000">)?($_GET</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">[</SPAN><SPAN style="COLOR: #800000">'h'</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">]</SPAN><SPAN style="COLOR: #000000">):</SPAN><SPAN style="COLOR: #000000">22</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;session_start()</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;Header(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Content-type:&nbsp;image/</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">.$type)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;srand((double)microtime()*</SPAN><SPAN style="COLOR: #000000">1000000</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;$randval&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;sprintf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">%04d</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;rand(</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">9999</SPAN><SPAN style="COLOR: #000000">))</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;session_register('session_verify')</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;if&nbsp;(&nbsp;is_array($_SESSION)&nbsp;)&nbsp;{&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;$_SESSION</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">[</SPAN><SPAN style="COLOR: #800000">'session_verify'</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">]</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;$randval</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;$session_verify&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">$_SESSION</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">[</SPAN><SPAN style="COLOR: #800000">'session_verify'</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">]</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;else&nbsp;{&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;$session_verify&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;$randval</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>if&nbsp;(&nbsp;$type!</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">'gif'&nbsp;&amp;&amp;&nbsp;function_exists('imagecreatetruecolor'))&nbsp;{&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>$im&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;@imagecreatetruecolor($width</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">$height)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;}else&nbsp;{&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;$im&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;@imagecreate($width</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">$height)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;$r&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Array(</SPAN><SPAN style="COLOR: #000000">225</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">255</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">255</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">223</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;$g&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Array(</SPAN><SPAN style="COLOR: #000000">225</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">236</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">237</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">255</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;$b&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Array(</SPAN><SPAN style="COLOR: #000000">225</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">236</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">166</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">125</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;$key&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;rand(</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">3</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;$backColor&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;ImageColorAllocate($im</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$r</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">[</SPAN><SPAN style="COLOR: #800000">$key</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">]</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">$g</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">[</SPAN><SPAN style="COLOR: #800000">$key</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">]</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">$b</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">[</SPAN><SPAN style="COLOR: #800000">$key</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">]</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">//背景色（随机）</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;$borderColor&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;ImageColorAllocate($im</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">//边框色</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;$pointColor&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;ImageColorAllocate($im</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">255</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">255</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">//点颜色</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;@imagefilledrectangle($im</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$width&nbsp;-&nbsp;</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$height&nbsp;-&nbsp;</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$backColor)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;@imagerectangle($im</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$width-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$height-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$borderColor)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;$stringColor&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;ImageColorAllocate($im</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">255</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">51</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">153</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;for($i</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">$i&lt;=10;$i++){&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;$pointX&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;rand(</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">$width-</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;$pointY&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;rand(</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">$height-</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;@imagesetpixel($im</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$pointX</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$pointY</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$pointColor)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;@imagestring($im</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">5</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">8</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">3</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$randval</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$stringColor)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;$ImageFun</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">'Image'.$type</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;$ImageFun($im)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;@ImageDestroy($im)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>?&gt;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV><BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;PHP随机密码生成&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>产生随机字串，可用来自动生成密码。<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>特点：<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">.&nbsp;可以指定密码包含数字或字符，默认为混和模式<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">.&nbsp;指定随意密码长度，默认长度为6位<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>代码如下：<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#-------------------------------------------<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#&nbsp;产生随机字串，可用来自动生成密码&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#&nbsp;默认长度6位&nbsp;字母和数字混合<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#&nbsp;$format&nbsp;ALL&nbsp;NUMBER&nbsp;CHAR&nbsp;字串组成格式<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#-------------------------------------------<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;function&nbsp;randStr($len</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">6</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">$format</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">'ALL')&nbsp;{&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;switch($format)&nbsp;{&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;case&nbsp;'ALL':<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;$chars</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~'</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;break;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;case&nbsp;'CHAR':<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;$chars</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-@#~'</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;break;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;case&nbsp;'NUMBER':<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;$chars</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">0123456789</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;break;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;default&nbsp;:<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;$chars</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~'</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;break</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;mt_srand((double)microtime()*</SPAN><SPAN style="COLOR: #000000">1000000</SPAN><SPAN style="COLOR: #000000">*getmypid())</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;$password</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;while(strlen($password)&lt;$len)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;$password.</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">substr($chars</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">(mt_rand()%strlen($chars))</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;return&nbsp;$password</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;}&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV></DIV><img src ="http://www.blogjava.net/bluesky/aggbug/26067.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2005-12-30 15:30 <a href="http://www.blogjava.net/bluesky/archive/2005/12/30/26067.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>smarty循环array-map显示</title><link>http://www.blogjava.net/bluesky/archive/2005/12/30/26053.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Fri, 30 Dec 2005 06:22:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2005/12/30/26053.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/26053.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2005/12/30/26053.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/26053.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/26053.html</trackback:ping><description><![CDATA[y.html 模板文件<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">ul</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{{section&nbsp;name=item&nbsp;loop=$menu_item}}}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;</SPAN><SPAN style="COLOR: #800000">a&nbsp;</SPAN><SPAN style="COLOR: #ff0000">href</SPAN><SPAN style="COLOR: #0000ff">="{{{$menu_item[item][0]}}}"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">{{{$menu_item[item][1]}}}</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">a</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;/</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{{/section}}}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;格式<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href="#"&gt;Index&lt;/a&gt;&lt;/li&gt;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href="#"&gt;Selected&nbsp;Content&lt;/a&gt;&lt;/li&gt;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href="#"&gt;Guestbook&lt;/a&gt;&lt;/li&gt;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href="#"&gt;Toggle&nbsp;Sidebar&lt;/a&gt;&lt;/li&gt;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href="#"&gt;Login&lt;/a&gt;&lt;/li&gt;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">ul</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV><BR>head.php<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&lt;?</SPAN><SPAN style="COLOR: #000000">php<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">require</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">lib/Smarty-2.6.11/libs/Smarty.class.php</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$smarty</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Smarty;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">$smarty-&gt;compile_check&nbsp;=&nbsp;true;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>//$smarty-&gt;debugging&nbsp;=&nbsp;true;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$smarty</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">left_delimiter&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">{{{</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$smarty</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">right_delimiter&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">}}}</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$site_title</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">中文</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">?&gt;</SPAN></DIV>ini.php<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&lt;?</SPAN><SPAN style="COLOR: #000000">php<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008080">define</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">SITE_TITLE</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">中文</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008080">define</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">SITE_LINK</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">''</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008080">define</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">AUTHER</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">bluesky</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008080">define</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">BABY</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">''</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008080">define</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">WATCH</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">''</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008080">define</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">BLOG_TITLE</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">HELLOWORLD,BLOG</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008080">define</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">BLOG_INDEX_LINK</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">HTTP://localhost:88/yy/xy.php</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">?&gt;</SPAN></DIV><BR>xy.php<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&lt;?</SPAN><SPAN style="COLOR: #000000">php<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">echo&nbsp;dirname(__FILE__);</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">require</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">head.php</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">require</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">ini.php</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$page</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">y.html</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008080">define</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">PAGE_TITLE</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">中国</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$smarty</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">assign(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">site_title</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">SITE_TITLE);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$smarty</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">assign(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">page_title</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">PAGE_TITLE);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$smarty</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">assign(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">blog_title</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">BLOG_TITLE);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$smarty</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">assign(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">blog_index_link</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">BLOG_INDEX_LINK);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$href</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">array</SPAN><SPAN style="COLOR: #000000">();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$value</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">array</SPAN><SPAN style="COLOR: #000000">();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$href</SPAN><SPAN style="COLOR: #000000">[</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">index.php</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">;&nbsp;</SPAN><SPAN style="COLOR: #800080">$value</SPAN><SPAN style="COLOR: #000000">[</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">首页</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$href</SPAN><SPAN style="COLOR: #000000">[</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">guest.php</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">;&nbsp;</SPAN><SPAN style="COLOR: #800080">$value</SPAN><SPAN style="COLOR: #000000">[</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">留言本</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$href</SPAN><SPAN style="COLOR: #000000">[</SPAN><SPAN style="COLOR: #000000">3</SPAN><SPAN style="COLOR: #000000">]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">about.php</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">;&nbsp;</SPAN><SPAN style="COLOR: #800080">$value</SPAN><SPAN style="COLOR: #000000">[</SPAN><SPAN style="COLOR: #000000">3</SPAN><SPAN style="COLOR: #000000">]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">关于</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$href</SPAN><SPAN style="COLOR: #000000">[</SPAN><SPAN style="COLOR: #000000">4</SPAN><SPAN style="COLOR: #000000">]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">link.php</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #800080">$value</SPAN><SPAN style="COLOR: #000000">[</SPAN><SPAN style="COLOR: #000000">4</SPAN><SPAN style="COLOR: #000000">]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">链接</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$map</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #008080">array_map</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #800080">$href</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #800080">$value</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #800080">$index</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;</SPAN><SPAN style="COLOR: #800080">$index</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #008080">count</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #800080">$c</SPAN><SPAN style="COLOR: #000000">);</SPAN><SPAN style="COLOR: #800080">$index</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">){<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">echo&nbsp;"&lt;a&nbsp;href=".$c[$index][0]."&gt;";<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;//echo&nbsp;$c[$index][1]."&lt;/a&gt;&lt;br/&gt;";</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">return;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$smarty</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">assign(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">menu_item</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #800080">$map</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$smarty</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">display(</SPAN><SPAN style="COLOR: #800080">$page</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">?&gt;</SPAN></DIV><img src ="http://www.blogjava.net/bluesky/aggbug/26053.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2005-12-30 14:22 <a href="http://www.blogjava.net/bluesky/archive/2005/12/30/26053.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP用smarty之后乱码问题</title><link>http://www.blogjava.net/bluesky/archive/2005/12/30/26043.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Fri, 30 Dec 2005 05:10:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2005/12/30/26043.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/26043.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2005/12/30/26043.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/26043.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/26043.html</trackback:ping><description><![CDATA[<P><IMG height=19 src="http://www.blogjava.net/Emoticons/angry_smile.gif" width=19 border=0></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">文件格式是utf8格式的</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">assign后会是显示乱码</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">外部css文件格式好像也不能是utf-8格式</SPAN></DIV><BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">用记事本打开</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">另存成编码ANSI格式的就好了</SPAN></DIV><IMG height=130 alt=icq81.gif src="http://www.blogjava.net/images/blogjava_net/bluesky/images/icq/icq81.gif" width=105 border=0><img src ="http://www.blogjava.net/bluesky/aggbug/26043.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2005-12-30 13:10 <a href="http://www.blogjava.net/bluesky/archive/2005/12/30/26043.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP数组和explode函数</title><link>http://www.blogjava.net/bluesky/archive/2005/12/29/25899.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Thu, 29 Dec 2005 08:35:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2005/12/29/25899.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/25899.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2005/12/29/25899.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/25899.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/25899.html</trackback:ping><description><![CDATA[<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&lt;?php<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>$province&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;array(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">北京</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">上海</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">天津</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">重庆</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">河北</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">山西</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">内蒙古</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">辽宁</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">吉林</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">黑龙江</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">江苏</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">浙江</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">安徽</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">福建</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">江西</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">山东</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">河南</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">湖北</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">湖南</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">广东</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">广西</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">海南</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">四川</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">贵州</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">云南</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">西藏</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">陕西</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">甘肃</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">宁夏</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">青海</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">新疆</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">香港</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">澳门</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">台湾</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">其他</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">echo&nbsp;count($province)</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">//数组成员个数</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">echo&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&lt;br/&gt;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>if(is_array($province)){//检测变量是否是数组<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">嗯,真是个数组啊</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>echo&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&lt;/br&gt;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>for($index</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">$index&lt;count($province);$index++){//数组循环</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">echo&nbsp;$province</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">[</SPAN><SPAN style="COLOR: #800000">$index</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">]</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">echo&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&lt;/br&gt;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>?&gt;</SPAN></DIV><BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&lt;?php<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>//利用&nbsp;explode&nbsp;函数分割字符串到数组<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>$source&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">hello1,hello2,hello3,hello4,hello5</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">//按逗号分离字符串</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">$hello&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;explode('</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">$source)</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>for($index</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">$index&lt;count($hello);$index++){</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">echo&nbsp;$hello</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">[</SPAN><SPAN style="COLOR: #800000">$index</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">]</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">echo&nbsp;"&lt;/br&gt;";</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>?&gt;</SPAN></DIV><BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&lt;?php<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>//函数挺实用的<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>//&nbsp;分隔符可以是斜线，点，或横线<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>$date&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">04/30/1973</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">list($month</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$day</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$year)&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;split&nbsp;('</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">[</SPAN><SPAN style="COLOR: #800000">/.-</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">]</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$date)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">echo&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Month:&nbsp;$month;&nbsp;Day:&nbsp;$day;&nbsp;Year:&nbsp;$year&lt;br&nbsp;/&gt;\n</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">?&gt;&nbsp;</SPAN></DIV><img src ="http://www.blogjava.net/bluesky/aggbug/25899.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2005-12-29 16:35 <a href="http://www.blogjava.net/bluesky/archive/2005/12/29/25899.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP写了个连接Mysql数据库的类</title><link>http://www.blogjava.net/bluesky/archive/2005/12/28/25729.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Wed, 28 Dec 2005 07:34:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2005/12/28/25729.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/25729.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2005/12/28/25729.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/25729.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/25729.html</trackback:ping><description><![CDATA[class.mysqlconnector.php<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">&lt;?</span><span style="COLOR: #000000">php<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;MysqlConnector{<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$dbname</span><span style="COLOR: #000000">;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">数据库名称</span><span style="COLOR: #008000"><br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$dbhost</span><span style="COLOR: #000000">;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">数据库地址</span><span style="COLOR: #008000"><br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$dbusername</span><span style="COLOR: #000000">;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">数据库用户名</span><span style="COLOR: #008000"><br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$dbpassword</span><span style="COLOR: #000000">;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">数据库密码</span><span style="COLOR: #008000"><br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000"><br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">&nbsp;MysqlConnector(){<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">dbname&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">test1</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">还是想写个set()方法来封装"私有"变量</span><span style="COLOR: #008000"><br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">dbhost&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">localhost</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">dbusername&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">root</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">dbpassword&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">;<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">&nbsp;connectMySql(){<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$openconn</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">mysql_pconnect</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">dbhost</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">dbusername</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"><span style="COLOR: #000000">dbpassword&nbsp;</span>)&nbsp;or&nbsp;</span><span style="COLOR: #0000ff">die</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">can&nbsp;not&nbsp;connect&nbsp;to&nbsp;mysql&nbsp;database!</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008080">mysql_select_db</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">dbname</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$openconn</span><span style="COLOR: #000000">);<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$openconn</span><span style="COLOR: #000000">;<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">?&gt;</span></div>
<br>test.php<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">&lt;?</span><span style="COLOR: #000000">php<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">require</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">class.mysql.connector.php</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #800080">$mysql_connector</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;MysqlConnector();<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #800080">$conn</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$mysql_connector</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">connectMySql();<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #800080">$rs</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">mysql_query</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">select&nbsp;*&nbsp;from&nbsp;student</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$conn</span><span style="COLOR: #000000">);<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$row</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">mysql_fetch_object</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$rs</span><span style="COLOR: #000000">)){<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">print</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #800080">$row</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">id&nbsp;</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/Images/dot.gif">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$row</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">name</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/Images/dot.gif">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$row</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">age</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;br/&gt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">?&gt;</span></div>
<br>student.sql<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">create</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">table</span><span style="COLOR: #000000">&nbsp;student&nbsp;(<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;id&nbsp;</span><span style="FONT-WEIGHT: bold; COLOR: #000000">int</span><span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #800000">10</span><span style="COLOR: #000000">)&nbsp;unsigned&nbsp;</span><span style="COLOR: #808080">not</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">default</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #ff0000">0</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #000000">,<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name&nbsp;</span><span style="FONT-WEIGHT: bold; COLOR: #000000">varchar</span><span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #800000">10</span><span style="COLOR: #000000">),<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;age&nbsp;</span><span style="FONT-WEIGHT: bold; COLOR: #000000">varchar</span><span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #800000">10</span><span style="COLOR: #000000">)<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">insert</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">into</span><span style="COLOR: #000000">&nbsp;student&nbsp;</span><span style="COLOR: #0000ff">values</span><span style="COLOR: #000000">&nbsp;(</span><span style="FONT-WEIGHT: bold; COLOR: #800000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #ff0000">xiaoli</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #000000">,</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #ff0000">23</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #000000">);<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">insert</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">into</span><span style="COLOR: #000000">&nbsp;student&nbsp;</span><span style="COLOR: #0000ff">values</span><span style="COLOR: #000000">&nbsp;(</span><span style="FONT-WEIGHT: bold; COLOR: #800000">2</span><span style="COLOR: #000000">,</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #ff0000">xiaoshi</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #000000">,</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #ff0000">23</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #000000">);&nbsp;&nbsp;&nbsp;<br><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">insert</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">into</span><span style="COLOR: #000000">&nbsp;student&nbsp;</span><span style="COLOR: #0000ff">values</span><span style="COLOR: #000000">&nbsp;(</span><span style="FONT-WEIGHT: bold; COLOR: #800000">3</span><span style="COLOR: #000000">,</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #ff0000">xiaobai</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #000000">,</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #ff0000">24</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #000000">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div>
<br>测试环境<br><a href="http://jaist.dl.sourceforge.net/sourceforge/appserv/appserv-win32-2.5.5.exe"><font style="BACKGROUND-COLOR: #f5f5dc">http://jaist.dl.sourceforge.net/sourceforge/appserv/appserv-win32-2.5.5.exe<br></font></a><br><a href="http://www.appservnetwork.com/"><font style="BACKGROUND-COLOR: #f5f5dc">http://www.appservnetwork.com/</font></a><br><br><font style="BACKGROUND-COLOR: #f5f5dc">Apache 2.0.55<br>MySQL 5.0.15<br>PHP 5.1.1<br>phpMyAdmin-2.6.4-pl4</font><br><br><font color=#ffa500 size=6><strong>运行效果</strong></font><br><img height=348 alt={2117F59D-8885-4110-AE41-85CB4E04D9FE}0.jpg src="http://www.blogjava.net/images/blogjava_net/bluesky/images/php/{2117F59D-8885-4110-AE41-85CB4E04D9FE}0.jpg" width=462 border=0><br>
<img src ="http://www.blogjava.net/bluesky/aggbug/25729.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2005-12-28 15:34 <a href="http://www.blogjava.net/bluesky/archive/2005/12/28/25729.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>记两个PHP函数</title><link>http://www.blogjava.net/bluesky/archive/2005/12/27/25633.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Tue, 27 Dec 2005 14:45:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2005/12/27/25633.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/25633.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2005/12/27/25633.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/25633.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/25633.html</trackback:ping><description><![CDATA[<P><FONT color=#ff0000 size=6><STRONG>file<IMG height=130 alt=icq81.gif src="http://www.blogjava.net/images/blogjava_net/bluesky/images/icq/icq81.gif" width=105 border=0><BR><BR></STRONG><A href="http://cn.php.net/manual/zh/function.file.php"><FONT style="BACKGROUND-COLOR: #f5f5dc"><STRONG>http://cn.php.net/manual/zh/function.file.php</STRONG></FONT></A><BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&lt;?php<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>//&nbsp;将一个文件读入数组。本例中通过&nbsp;HTTP&nbsp;从&nbsp;URL&nbsp;中取得&nbsp;HTML&nbsp;源文件。<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>$lines&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;file('http://www.example.com/')</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">//&nbsp;在数组中循环，显示&nbsp;HTML&nbsp;的源文件并加上行号。<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>foreach&nbsp;($lines&nbsp;as&nbsp;$line_num&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&gt;&nbsp;$line)&nbsp;{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;echo&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Line&nbsp;#&lt;b&gt;{$line_num}&lt;/b&gt;&nbsp;:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;.&nbsp;htmlspecialchars($line)&nbsp;.&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&lt;br&nbsp;/&gt;\n</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>//&nbsp;另一个例子将&nbsp;web&nbsp;页面读入字符串。参见&nbsp;file_get_contents()。<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>$html&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;implode(''</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;file&nbsp;('http://www.example.com/'))</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">?&gt;&nbsp;</SPAN></DIV></FONT><BR><FONT size=6><FONT color=#ff0000><STRONG>正则表达式</STRONG></FONT><FONT color=#ff0000><STRONG>查找替换<BR></STRONG><A href="http://cn.php.net/manual/zh/function.preg-replace.php"><FONT style="BACKGROUND-COLOR: #ffc0cb" color=#ff0000 size=2>http://cn.php.net/manual/zh/function.preg-replace.php</FONT></A><BR><BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&lt;?php<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>$string&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">April&nbsp;15,&nbsp;2003</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">$pattern&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">/(\w+)&nbsp;(\d+),&nbsp;(\d+)/i</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">$replacement&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\${1}1,\$3</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">print&nbsp;preg_replace($pattern</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$replacement</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;$string)</SPAN><SPAN style="COLOR: #008000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>/*&nbsp;Output<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">======</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>April1</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">2003</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;*/<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>?&gt;&nbsp;</SPAN></DIV></FONT></FONT><img src ="http://www.blogjava.net/bluesky/aggbug/25633.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2005-12-27 22:45 <a href="http://www.blogjava.net/bluesky/archive/2005/12/27/25633.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转载]PHP模板引擎SMARTY</title><link>http://www.blogjava.net/bluesky/archive/2005/12/27/25575.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Tue, 27 Dec 2005 07:24:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2005/12/27/25575.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/25575.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2005/12/27/25575.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/25575.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/25575.html</trackback:ping><description><![CDATA[<FONT style="BACKGROUND-COLOR: #ffffff" color=#ff0000 size=6>出处</FONT> <A href="http://www.5ivb.net/Info/130/Info39210/"><FONT style="BACKGROUND-COLOR: #deb887" color=#006400>http://www.5ivb.net/Info/130/Info39210/</FONT></A><BR><BR>用PHP实现MVC开发模式的逻辑层和表示层有多种模板引擎可供选择， 但是官方引擎SMARTY诞生后，选择就有了变化。它的理念和实现都是 相当"前卫"的。本文主要讨论SMARTY之于其他模板引擎的不同特点， 简要介绍了该引擎的安装及使用，并用一个小的测试案例对比了 SMARTY和PHPLIB template的速度和易用性。 <BR><BR>一、MVC需要模板 <BR>MVC最早是在SmallTalk语言的开发过程中总结出的一种设计模式，MVC分别代 表了"模型"、"视图"和"控制"，目的就是让不同的开发角色在大中型项目中各司 其职。在网络应用程序的开发中，可以用下图来表示各概念之间的关系。 <BR><BR><BR>该图展示了一个简单的WEB应用程序，用户在浏览器上看到信息是数据库服务 器上的内容，但在这之前经过了应用服务器加工。开发人员负责的就是建立数 据结构、处理数据的逻辑以及表示数据的方法。 <BR><BR>96年CGI在中国开始流行的时候，早期的WEB程序员都是从HTML开始自学成材 的，在PERL中print一行行的HTML并不是一件难事，但是随着网络的一步步提 速，页面大小也从当初的二、三十K暴涨了十倍。写CGI程序就产生了一个迫切 的要求：分开PERL和HTML源码。于是，社会进步体现在开发小组内部的分工 上。由于美工和程序员对互相的工作并不是十分熟悉，在进行合作的过程中需 要用一种约定的"语言"进行交流。 <BR><BR>这种语言并不是我们的母语或者英语，术语叫做"模板"，逻辑和表示依靠它联 系。它是结合了HTML和脚本语言特征的一种表达方式。通过这种方式，表示层 可以按照用户所希望的格式来显示经过逻辑层处理过的数据。如果你有 Windows平台下MFC的开发经验,那么一定会很熟悉Document/Document Template/View的封装，这就是一个很典型的MVC例子。对于Web应用来说，个 人认为J2EE中的EJB/servlets/JSP是最强大的，当然还有简洁优美的Structs。 另一个很有名的实现就是COM/DCOM+ASP，这个组合在我国是最多人使用 的。 <BR><BR>通过几种MVC实现在WEB应用程序里的对比，可以得到一个关于模板的概念： 一组插入了HTML的脚本或者说是插入了脚本HTML，通过这种插入的内容来表 示变化的数据。下面给出一个模板文件的例子，这个模板经过处理后在浏览器 里显示"Hello, world!" <BR><BR>引言： <BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">html</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">head</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">title</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">$greetings</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">title</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">head</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">body</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>$greetings&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">body</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">html</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV><BR>这里暂且省略处理方式，在后面做专门对比讨论。 <BR><BR>二、为什么选SMARTY? <BR>对PHP来说，有很多模板引擎可供选择，比如最早的PHPLIB template和后起之 秀Fast template，经过数次升级，已经相当成熟稳定。如果你对目前手中的模 板引擎很满意，那么......也请往下看，相信你作为一个自由软件爱好者或者追求 效率和优雅的开发者，下面的SMARTY介绍多少会有点意思。 <BR><BR>除了个人偏好的影响，我一直倾向于使用官方标准的实现，比如APACHE的XML 引擎Axis。好处就是可以获得尽可能好的兼容性(比如早期MFC对于Win3x的兼 容性就比其它的应用程序框架好，当然现在各种版本都很完善了)。SMARTY发 布之前我一直使用的是PEAR 中的Integrated Template eXtension。这个引擎和 PHPLIB template、Fast template几乎是兼容的，从模板的语法到对模板的处理 同出一辙：都是将模板读入内存然后调用parse()函数，用数据对预置的标记进 行替换。 <BR><BR>下面看看SMARTY是怎么做的。接到request后，先判断是否第一次请求该url， 如果是，将该url所需的模板文件"编译"成php脚本，然后redirect；如果不是， 就是说该url的模板已经被"编译"过了，检查不需要重编译后可以马上redirect， 重编译条件可以自己设定为固定时限，默认的是模板文件被修改。 <BR><BR>怎么样，看起来是不是有点眼熟？想起来了──这不就是JSP的原理嘛！的确， 这种"编译"用在PHP这样的解释性脚本引擎上显得匪夷所思，但是仔细想 想，JAVA不也是由JVM解释执行的吗？这就叫"没有做不到，只有想不到"。 <BR><BR>既然谈到了JAVA，就再对PHP的未来发表一点看法。PHP官方网站上宣布了要 在2003年年底发布PHP5.0版。这个版本拥有很多崭新的特性：比如异常处理， 命名空间，更加面向对象等等。可以说越来越向JAVA靠拢，SMARTY也是新特 性之一，使得PHP更适用于大中型项目的开发。但是似乎离我当初选择它的原 因──灵巧易用──越来越远了。但就一个软件的生存周期来看，PHP正处在 成长期，开发者赋予它更多的功能，以期能胜任商业应用是利大于弊的。作为 PHP的忠实用户，肯定不希望PHP总是被人指责"能力不足"吧？ <BR><BR>为什么选择SMARTY，仅仅因为它很像JSP？当然有更为充分的理由。首先，除 了第一次编译的成本比较高之外，只要不修改模板文件，编译好的cache脚本就 随时可用，省去了大量的parse()时间；其次SMARTY像PHP一样有丰富的函数 库，从统计字数到自动缩进、文字环绕以及正则表达式都可以直接使用；如果 觉得不够，比如需要数据结果集分页显示的功能，SMARTY还有很强的扩展能 力，可以通过插件的形式进行扩充。 <BR><BR>事实胜于雄辩。我设计了一个测试程序，通过速度和开发难度这两个因素对比 了一下SMARTY和PHPLIB template，选PHPLIB template的原因是在patrick的 文章《在PHP世界中选择最合适的模板》中有一个PHPLIB template对Fast template 的竞赛，结果PHPLIB template大获全胜，这使得SMARTY有了一个很好的对 手。在测试之前，先谈一下在安装过程中需要注意的问题。 <BR><BR>三、可能遇到的问题 <BR>在SMARTY的官方网站上，有详尽的用户手册，可以选择在线HTML和PDF格式 的版本。这里就不再涉及手册上已有的内容，只是把初次使用可能遇到的问题 做个解释。 <BR><BR>第一个问题就很要命：提示说找不到所需文件？并不是每一个人都按照 SMARTY默认目录结构来写应用的。这里需要手工指定，假设目录结构如下： <BR><BR><BR>就需要在index.php里指定目录结构： <BR>引言：&nbsp;<BR><BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">$smart-&gt;template_dir&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">smarty/templates/</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">$smart-&gt;compile_dir&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">smarty/templates_c/</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">$smart-&gt;config_dir&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">smarty/configs/</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">$smart-&gt;cache_dir&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">smarty/cache/</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN></DIV><BR>第一个问题解决了，紧接着就是第二个：我刚用Dreamweaver生成的漂亮模板 怎么不能用？并不是模板文件有什么问题，而是因为SMARTY默认的标记分隔 符是{}，不巧的是Javascript肯定包含这个标记。好在我们可以用任意字符当作 分隔符，再加上这两句： <BR>引言： <BR><BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">$smart-&gt;left_delimiter&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">{/</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">$smart-&gt;right_delimiter&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">/}</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN></DIV><BR>这下安装就基本完成，没问题了。 <BR><BR>四、反衬和类比 <BR>先构思一下对测试的设计。主要的评比因素当然是速度了。为了进行速度测 试，采取了算术平均数的作法。在测试页面中重复将页面生成N遍，再对比总页 面生成时间。另一个重要因素是易用性(至于扩展性不用比较已经有结果了)，所 以使用的模板不能太小。我用的是我个人主页的的页面，一个用 Firework+Dreamweaver生成的HTML文件，大小约7K。其中的变量设置也采取 最常用的区块，在PHPLIB template里叫block,而SMARTY则称section。别小看 这称呼的不同，易用性标准分两块：模板文件和脚本文件的语法是否简明易 用。 <BR><BR><BR>下面就深入到测试中来。先看看两种模板文件的语法：蓝条左边是PHPLIB template的模板，右边属于SMARTY。个人偏好是不一样的，所以这里不作评 论。着重对比一下脚本里的处理语句，先看PHPLIB template的: <BR>引言： <BR><BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">$tpl-&gt;set_file(''phplib''</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;''bigfile.htm'')</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">$tpl-&gt;set_block(''phplib''</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;''row''</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;''rows'')</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">for&nbsp;($j&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;$j&nbsp;&lt;&nbsp;10;&nbsp;$j++){&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">$tpl-&gt;set_var(''tag''&nbsp;</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">$j</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">$tpl-&gt;parse(''rows''</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;''row''</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;true)</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">}&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>$tpl-&gt;parse(''out''</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">&nbsp;''phplib'')</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">$tpl-&gt;p(''out'')</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV><BR><BR>下面是SMARTY的： <BR><BR>引言： <BR><BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">$smart-&gt;assign(''row''</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">$row)</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">$smart-&gt;display(''bigfile.htm'')</SPAN><SPAN style="COLOR: #008000">;</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV><BR><BR>SMARTY只用了tags和row两个变量，而PHPLIB template则多了模板文件的 handler，还有一个莫名其妙的out。说实在的这个out我当初学的时候就不知道 为什么要存在，现在看起来，还是别扭。为什么SMARTY少那么多处理语句 呢？答案是工作由引擎完成了。如果你喜欢钻研源程序，可以发现在 Smarty_compiler.class.php里有一个名叫_compile_tag()的函数，由它负责把 section这个标签转换成php语句。这不是一个普通的标签，它带有参数和数 据，节省了脚本编程的工作量，而模板标签上的工作量相差又不大，可以判定 在易用性上SMARTY高出一畴。 <BR><BR>下面该轮到我们最关注的速度了，毕竟对于一个熟练的web开发者来说，掌握再 困难的工具不过是时间问题，何况模板引擎这种学习曲线平缓的技术。而速度 则是web应用程序的生命，尤其是模板引擎使用在并发访问量很大的站点上，这 点就更重要了。测试开始前，我觉得PHPLIB template会在这一环节上胜出，因 为它经历了很多次升级，已经基本没有什么bug,而且SMARTY的引擎个头太 大，不像它的对手只有两个文件。 <BR><BR>果然，测试结果如下图，PHPLIB template有25%的速度优势： <BR><BR><BR>但不会一直这样，我又按了一次刷新，这次得到了不一样的结果： <BR><BR><BR>PHPLIB基本没变化，但是SMARTY提高了25%的速度。继续刷新，得到的都是 类似于第二次的结果：SMARTY比PHPLIB template 快上近10%。我想这就是编 译型比解释型快的原理了。SMARTY引擎本身就很大，加上还要把模板编译成 php文件，速度当然比不上小巧的PHPLIB template。但这只是第一次的情况。 第二次接到请求的时候，SMARTY发现该模板已经被编译过了，于是最耗时的 一步被跳过了，而对手还要按部就班地进行查找和替换工作。这是编译原理里 讲到的很经典的"用空间换时间"例子。 <BR><BR>五、结论 <BR>结论就是如果你已经爱上SMARTY了，那么还等什么呢？当然并不是说它就全 能，就如同我用MVC模式来写我的个人网站，非但没有减少工作量，反而总是 要为不同层次间的耦合劳神。 <BR><BR>SMARTY不适合什么呢？举个手册里的经典例子：天气预报网站。我还想到一 个：股市大盘。在这种网站上用SMARTY会由于经常的重编译而效率偏低，还 是PHPLIB template更为适合。 <BR><BR>本文并不是为了对比两种引擎，而是为了说明SMARTY的优势。使用它最有意 义之处在于它是PHP新体系的一部份，作为一支独立的力量，除了.NET和JAVA ONE这两大体系之外，大中型web开发还有别的选择。这对于GNU项目来说， 其意义无异于刘邓大军千里跃进大别山。 <BR><BR>参考文献 <BR><BR>SMARTY官方站点：smarty.php.net <BR>王晨：《在PHP世界中选择最合适的模板》 <BR>本文中测试程序下载：test.tar.bz2 <BR>http://phpe.net/uploads/attach/article_1058233528.bz2 <BR>About the author <BR>于博翔，笔名于莱来自对外经济贸易大学信息学院。GNU痴迷者，喜欢练习各种编程语 言，研究各种体系框架。 <BR><BR>发帖数：1275 回复：與許多的PHP script 都將使用Smarty為核心引擎,而Smarty到底是甚麼? 2003-08-10 14:07 <BR><BR>在PHP世界中选择最合适的模板--比较PHPLIB Template和FastTemplate <BR><BR><BR><BR>PHP工程中的模板应用，是进行中型乃至大型项目中建议采用的处理表现层的好办法。但 是具体到模板的实施，采用何种现有的模板技术却需要进行一番比较。 <BR><BR>PHP世界中比较受关注的模板处理有PHPLIB Template和FastTemplate两种，我们对技术的易用性和速 度进行了评测--想知道结果吗？ <BR><BR>事情的起因：你用过FastTemplate吗？ <BR>对于PHP工程中的模板应用，其实我和我的同事们已经在许多的项目中接触过--关于它的好处，我想无论 是在实际开发阶段还是上升到设计模式的角度都已经有很多"前辈先哲"讨论过了。就项目实施而言，在一 些中型甚至大型的项目中，有效的将HTML（还有其他文本形式的表现层）和PHP代码分开，不仅在开发 阶段可以分别提高界面设计人员和应用程序编写人员的工作效率，更会给项目的测试和维护带来巨大的便 利。 <BR><BR>但是--本文的目的不是讨论模板的优缺点，也不是作为指导性的教程讲授如何在PHP项目中使用模板，而 是以应用的视角比较两种PHP世界中最为流行的模板处理方式（其实只不过是两种模板类）：PHPLIB Template和FastTemplate。 <BR><BR>其实我一直都在"安静"的使用着PHPLIB Template--很稳定而且看上去速度也不错，以至于我并不想再去 不安的寻找可能更好的替代品--虽然我也知道这个地球上还有FastTemplate这样的东西（而且还在Perl的 世界中大名鼎鼎）。直到有一天，有一个同事问我："不知道FastTemplate怎么样？为什么我们不试试 FastTemplate呢？" <BR><BR>"好吧，就让我们试试！"不过作为一个稳妥的方法，在任何新的模式或者方法引入项目之前，最好能够更 加全面的了解它，以及找到一个或者几个足够说服自己和同事去采用它的理由--对于FastTemplate也不例 外。 <BR><BR>主角出场：了解PHPLIB Template以及FastTemplate <BR>前面已经说过，我已经使用PHPLIB有一段时间了--我想屏幕前的你也许和我一样，也对这个优秀的工具类 库印象很深吧！同样，当我开始寻求模板的解决办法时，很自然的就会在最接近身边的工具箱里搜寻，于 是我找到了PHPLIB中的Template类。在最初的很快浏览完它提供的API之后（当然还得感谢PHPLIB详尽 的文档），我就开始了使用它的历程--直到现在。 <BR><BR>而FastTemplate似乎名气更响亮一些，在其发迹的Perl世界中自然是这样，在PHP世界中似乎也是，单单 从这一点上就足够让人相信它的能力了。 <BR><BR>关于两者的使用办法，本来我想在这里多废话几句的；但是毕竟觉得自己恐怕专门写出两篇教程来也没有 现有的教程受欢迎--在本文的参考资料中有关于PHPLIB Template和FastTemplate的有名教程，如果你自 认还没有对这两种模板或者其中的一种有所认识，建议你先去看看那两篇文章，应该会得到不少有益的模 板应用知识。 <BR><BR>（一番鼠标点击以及眼球转动甚至亲自编写测试代码之后，）现在你对两种模板都有了一些了解，也许已 经发现了它们之间的很多相似之处，在下面我就会将这些地方归纳一下。 <BR><BR>变量的设置 <BR>很明显，{FOO}或者{BAR}的形式在两种模板中都是指定的形式；也就是说，两种模板处理方式 中，模板文件本身的外貌应该可以是一致的（比如都是HTML文件中间含有将要被替换的以{}标识 的变量）。 <BR>模板类的初始化（类的构建器） <BR>都需要在构建模板类的时候指定模板文件存在的目录位置。 <BR>变量的替换 <BR>模板处理中最常用的就是变量替换，两种方式除了方法名不同之外（PHPLIB Template采用 set_var()，而FastTemplate采用assign()），用法几乎也是一致的--可以采用(key, value)的方式， 也可以直接传递一个数组(array(key=&gt;value))。 <BR>模板文件的处理 <BR>都是采用为每一个模板文件指定一个句柄（handler）的办法，同时句柄也可以作为变量的值替换 另一模板文件中的变量。 <BR>解析、输出过程 <BR>都是需要调用parse()方法（这个方法名竟然是相同的）将需要输出的模板文件解析后赋值给一个 句柄，然后调用各自输出的方法（PHPLIB Template中是p()，FastTemplate中是FastPrint()）输 出该句柄的内容并结束处理。 <BR>重复解析的过程 <BR>比如从数据库中取出几条记录需要显示而模板文件只有可替换的一行变量的时候，就很需要这样的 功能。两者都具有这样的功能，只是使用时稍稍有些不同而已（PHPLIB Template采用 parse(handler, value, true)，而FastTemplate采用parse(handler, .value)在值的前面多加一个 点），应该说PHPLIB Template的方法构造得相对优美一点。 <BR>区块解析的过程（或者可以称作动态解析） <BR>想像一下你需要从数据库中取出符合条件的数据并显示在网页中--但是因为条件会不尽相同，你并 不能明确的知道会有多少条数据--这时候如果你又要采用模板，那么区块就是最好的选择。它是在 模板中用特定的符号定义的部分，这一部分可以反复的被解析并添加到（而不是前一次的解析被后 一次覆盖）输出网页中。区块也许就像下面显示的一样（左边是PHPLIB Template采用的区块设 置，而右边则是FastTemplate采用的）： <BR><BR><BR><BR>好吧，如果你对以上苍白的文字介绍还是有些摸不着头脑，那么我们就来看看两个详尽的模板处理的例程 吧！（如果你有兴趣对后面的测试代码进行发掘，就会发现其实以下的两个例子都来自那里） <BR><BR><BR>怎么样，是不是感觉几乎是一致的？下面是区块解析的例子，你也会发现同样的效果： <BR><BR><BR>我们的测试目标和结果 <BR>结束了对PHPLIB Template和FastTemplate的了解，应该可以进入本文的正题了--在应用环境中当然应该 选择易于使用同时速度理想的部件构建系统，那么对于这样的两种类似技术，进行评测非常有必要。评测 应该是由两部分组成：技术的使用难度和速度的快慢程度--前者是评论的部分，而后者是测试的部分。对 于前者，我们主要针对两个类提供的API进行评论；对于后者，我们会让测试的数据来说话，当然这中间 免不了需要编写一些简单的测试代码。 <BR><BR>回合一：技术的易用性 <BR>这一回合主要是探讨PHPLIB Template和FastTemplate提供的API的使用情况。应该说，前者提供的API 更符合PHP的一些常见编码惯例（特别是当你的项目中采用了PHPLIB的其他类时，这样的规范性会对整 个项目有好的影响）；而后者的一些方法名总觉得有些别扭（希望你不要觉得这只是我的狭隘看法，比如 FastPrint()等等），同时方法的参数也不是非常"地道"，这一点你也可以从刚才的代码看出来。 <BR><BR>另外一点需要指出的是，对于模板区块的解析，FastTemplate直到最近的版本才开始支持。也就是说，如 果你采用了之前的版本，在处理诸如数据库中记录的输出等内容时，不得不把这块内容独立存储在某处， 然后在模板分析处理时附加上这个文件--真是一件让人难受的事情，尤其是对网页设计人员而言。 <BR><BR>当然还有一点需要考察--那就是对于PHP版本的支持。PHPLIB产生在PHP3的时代，这一点和 FastTemplate差不多；但是根据我们的应用，PHPLIB在现在的PHP4环境下运行相当好，而 FastTemplate的网页上则显示了一些信息表明对于PHP4也许它还有一些BUG存在。 <BR><BR>好了，讲了这么多（也许你会觉得都是FastTemplate的坏话），这个回合的胜利者很明显：PHPLIB Template，尤其是你同时在使用PHPLIB的其他类时，这样的技术易用性更加明显（你将不会对这些出自 同一个开发小组的API感到陌生）。 <BR><BR>回合二：处理速度 <BR>也许这才是很多人最关注的部分--在这个回合中，我们会采用两种模板处理的方式：一种是常规的分析、 替换，另一种是对区块的解析、替换--同时这样的两种方式也是在实际系统中应用最多的：前者是一般的 页面处理，后者是关于数据库内容的输出处理。同时，由于两种模板类采用的模板文件的格式基本相同， 使得我们可以提供几乎一致的模板文件分别供两种模板解析，更增加了测试的可信度。 <BR><BR>开展这样的速度测试之前会拟定一个测试方案，简单说来就是对于两种处理方式分别编写两个PHP测试页 面，同时有一个控制测试的页面多次调用这两个页面并记录时间供采集测试数据。（如果有兴趣你还可以 参考以下详细的测试方案，也许会对你深入了解这次测试有所帮助） <BR><BR>小结--在整个测试系统完成之后，我们应该能够得到/test目录中如下的文件清单： <BR><BR>（有点复杂的测试方案） <BR><BR>首先是确定测试的硬件和软件环境--硬件肯定是自己的机器了，Intel Celeron 733MHz， 256M RAM，40G HDD；软件平台中OS为Win2K Pro，Web服务器为Apache+PHP，且以 模块方式运行。 <BR><BR>其次是规划这次测试的系统--当然先在Web服务器的文档根目录下开一个tpl_test的新目录用 以放置这个测试的所有文件；然后在/tpl_test下建立include目录以存放两个模板类文件（我 们测试的核心，以.inc.php为文件扩展名）以及一个测试类文件（包括了计时和记录日志以 及读取日志并分析等功能，以.inc.php为文件扩展名）和一个数据文件（为区块解析的测试 做准备，主要包含了一个二维数组，同样以.inc.php为文件扩展名），建立ihtml目录存放使 用的模板文件（需要被解析的模板文件，以.ihtml为文件扩展名），建立logs目录存放测试产 生的日志（后面就是发现，其实测试的数据就是由对这些日志的分析得到的，以.log为文件 扩展名）。当然，两种模板的处理PHP文件就放在/test目录下。这次测试最关键的一点是， 还需要建立一个PHP文件，对以上提到的负责模板处理的文件进行数次调用：比如一个文件 fast_test.php是采用FastTemplate解析模板的，而phplib_test.php是采用PHPLIB Template 解析的，那么这个得出结果的PHP文件就负责多次以HTTP的方式请求以上的两个页面以获 得测试数据。 <BR><BR>选择待解析的模板和PHP程序编写--因为两种模板处理方式对于模板文件本身的格式要求几 乎一致（比如待替换变量都采用{VAR}的形式等等），因此可以尽量保证同一测试中两者选 用的模板尽可能相同以谋求测试的最大公正性；同时在前文提到，为模拟现实系统中常用的 两种模板应用：一般的页面处理和对数据库内容的输出处理，测试使用的模板文件也分成两 种：一种是普通的带有一些待替换变量的模板文件，另一种是带有区块的需要根据应输出的 内容反复替换的模板文件。同样对于这两种模板文件，也需要分别编写两种不同的PHP文件 进行解析。 <BR><BR>测试方法--在浏览器中向/test/result.php提出请求，需要带参数type=[simple|complex]，在 返回的结果中即可看到两种模板在简单或者复杂模式下的测试结果。 <BR><BR>Level 1 <BR>Level 2 <BR>Level 3 <BR>Remark <BR><BR>/test <BR><BR><BR>测试系统的根目录 <BR><BR><BR><BR><BR><BR><BR><BR>result.php <BR><BR>进行测试并产生结果的PHP文件，测 试时只需要在浏览器中请求该页面即 可获得测试信息 <BR><BR><BR>simple__test_phplib.php <BR><BR>使用PHPLIB Template对一般模板进 行分析的PHP文件 <BR><BR><BR>simple__test_fast.php <BR><BR>使用FastTemplate对一般模板进行分 析的PHP文件 <BR><BR><BR>complex__test_phplib.php <BR><BR>使用PHPLIB Template对带区块模板 进行分析的PHP文件 <BR><BR><BR>complex__test_fast.php <BR><BR>使用FastTemplate对带区块模板进行 分析的PHP文件 <BR><BR><BR><BR><BR><BR><BR><BR>/include <BR><BR>包含PHP类文件.inc.php <BR><BR><BR><BR>phplibTemplate.inc.php <BR>PHPLIB Template类文件 <BR><BR><BR><BR>FastTemplate.inc.php <BR>FastTemplate类文件 <BR><BR><BR><BR>TplTest.inc.php <BR>测试中需要使用的测试类，包含诸如 计时、读取/分析日志等方法。 <BR><BR><BR><BR>data.inc.php <BR>测试带区块模板时采用的数据文件。 <BR><BR><BR><BR><BR><BR><BR><BR>/ihtml <BR><BR>包含模板文件.ihtml <BR><BR><BR><BR>simple_phplib.ihtml <BR>采用PHPLIB Template处理的一般模 板文件 <BR><BR><BR><BR>simple_fast.ihtml <BR>采用FastTemplate处理的一般模板文 件 <BR><BR><BR><BR>complex_phplib.ihtml <BR>采用PHPLIB Template处理的带区块 的模板文件 <BR><BR><BR><BR>complex_fast.ihtml <BR>采用FastTemplate处理的带区块的模 板文件 <BR><BR><BR><BR><BR><BR><BR><BR>/logs <BR><BR>包含日志文件.log <BR><BR><BR><BR>simple_phplib.log <BR>采用PHPLIB Template处理一般模板 生成的日志 <BR><BR><BR><BR>simple_fast.log <BR>采用FastTemplate处理一般模板生成 的日志 <BR><BR><BR><BR>complex_phplib.log <BR>采用PHPLIB Template处理带区块模 板生成的日志 <BR><BR><BR><BR>complex_fast.log <BR>采用FastTemplate处理带区块模板生 成的日志 <BR><BR>经过了测试系统的设计和编写，并且向负责网页设计的同事讨来两个模板之后，我们就可以访问这个系统 了--前期的辛勤劳动使得现在观看结果的工作只需要在浏览器的地址栏中打入 http://localhost/tpl_test/ result.php?type=[simple|complex] （如果你是在其他的非本地服务器中进行这个测试，那么域名应采用 所在服务器的域名--比如我自己的机器叫做patrick等等）。下面是我自己在某一次的测试中获得的结 果：（测试结果数据解释） <BR><BR>名称 <BR>解释 <BR>备注 <BR><BR>amount <BR>测试总数（连续请求该页面总数） <BR>该参数可在result.php文件中修改 <BR><BR>max_seq <BR>最大处理时间的序号 <BR>范围在1－amount之间 <BR><BR>max_value <BR>最大处理时间的值 <BR>峰值数据供参考 <BR><BR>min_seq <BR>最小处理时间的序号 <BR>范围在1－amount之间 <BR><BR>min_value <BR>最小处理时间的值 <BR>峰值数据供参考 <BR><BR>average <BR>平均处理时间 <BR>测试中最有价值的数据 <BR><BR><BR>当然，如果你觉得一次测试的结果并不可靠，可以反复按下浏览器的刷新按钮，就能够观察到不同测试的 <BR><BR>结果（理论上应该是相差无几）。 <BR><BR>测试结果以及颁发"XX选择奖" <BR>好了，在偏重速度测试的回合二中PHPLIB Template以惊人的2倍的速度战胜了FastTemplate；而同时在 第一回合中PHPLIB Template有以良好的API设计和易用性占得上风。结果显而易见--我们的选择奖当然颁 发给了PHPLIB Template，同时这次的测试也让我们对PHPLIB这个类库设计有了更深的了解。 <BR><BR>主观评价 <BR>既然有了结果，那么FastTemplate自然也就不能进入我们的项目了--虽然从结果上看来我们花费了半天的 时间得到了一个毫无变化的结果（PHPLIB Template继续很好的在项目中使用），但是测试的过程却是很 有价值的，特别是采用PHP进行测试的方法，应该会在以后的类似决策中起到一定参考作用。 <BR><img src ="http://www.blogjava.net/bluesky/aggbug/25575.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2005-12-27 15:24 <a href="http://www.blogjava.net/bluesky/archive/2005/12/27/25575.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>我用PHP写了个类,封装方法-POPO传统的旧的PHP对象?</title><link>http://www.blogjava.net/bluesky/archive/2005/12/27/25569.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Tue, 27 Dec 2005 06:36:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2005/12/27/25569.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/25569.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2005/12/27/25569.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/25569.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/25569.html</trackback:ping><description><![CDATA[class.people.php<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&lt;?</SPAN><SPAN style="COLOR: #000000">php<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;People{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">var</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">$name</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">var</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">$age</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">function</SPAN><SPAN style="COLOR: #000000">&nbsp;People(</SPAN><SPAN style="COLOR: #800080">$name</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #800080">$age</SPAN><SPAN style="COLOR: #000000">){<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #800080">$this</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">setName(</SPAN><SPAN style="COLOR: #800080">$name</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #800080">$this</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">setAge(</SPAN><SPAN style="COLOR: #800080">$age</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">function</SPAN><SPAN style="COLOR: #000000">&nbsp;getName(){<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">$this</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">name;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">function</SPAN><SPAN style="COLOR: #000000">&nbsp;setName(</SPAN><SPAN style="COLOR: #800080">$name</SPAN><SPAN style="COLOR: #000000">){<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #800080">$this</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">name&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">$name</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">function</SPAN><SPAN style="COLOR: #000000">&nbsp;getAge(){<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">$this</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">age;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">function</SPAN><SPAN style="COLOR: #000000">&nbsp;setAge(</SPAN><SPAN style="COLOR: #800080">$age</SPAN><SPAN style="COLOR: #000000">){<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #800080">$this</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">age&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">$age</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">?&gt;</SPAN></DIV>index.php调用这个类<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&lt;?</SPAN><SPAN style="COLOR: #000000">php<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">require</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">class.people.php</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$xiaoli</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;People(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">李</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">23</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">echo</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">His&nbsp;name&nbsp;is</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #800080">$xiaoli</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">getName();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">echo</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">His&nbsp;age&nbsp;is</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #800080">$xiaoli</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">getAge();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">?&gt;</SPAN></DIV><img src ="http://www.blogjava.net/bluesky/aggbug/25569.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2005-12-27 14:36 <a href="http://www.blogjava.net/bluesky/archive/2005/12/27/25569.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>安装phpwiki</title><link>http://www.blogjava.net/bluesky/archive/2005/12/26/25497.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Mon, 26 Dec 2005 13:28:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2005/12/26/25497.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/25497.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2005/12/26/25497.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/25497.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/25497.html</trackback:ping><description><![CDATA[<P><FONT color=#ff1493><A href="http://cosoft.org.cn/html/osl/projects.php?group_id=10193"><STRONG><FONT style="BACKGROUND-COLOR: #f5f5dc">PhpWiki</FONT></STRONG></A><FONT style="BACKGROUND-COLOR: #f5f5dc"><FONT color=#000000> - PhpWiki is a WikiWikiWeb clone written in PHP. A Wiki is a Web site where anyone can edit or create the pages through the Web browser, with no authentication. PhpWiki works right out of the box with zero configuration, and comes with a set of default pages. It's useful for collaborating on documentation on a project, having freeform discussions, and easy editing and searching. <BR><BR><BR>
<TABLE cellPadding=0 width="100%" border=0>
<TBODY>
<TR vAlign=top>
<TD><FONT class=mgl>来源：http://freshmeat.net/projects/phpwiki/?topic_id=22%2C27%2C92%2C847%2C90 <BR>PhpWiki是一个用PHP写的WikiWikiWeb的克隆产品。Wiki是一个Web 站点，任何人可以通过一个浏览器编辑和修改网页。PhpWiki无需复杂的设置，生成默认页面，它使合作项目变得更加方便，可以自由的讨论，方便的编辑和检索。&nbsp;</FONT></TD></TR>
<TR vAlign=top>
<TD>
<UL>
<LI>Development Status: <A href="http://cosoft.org.cn/html/osl/browse.php?form_cat=11">5 - Production/Stable</A><BR>
<LI>Environment: <A href="http://cosoft.org.cn/html/osl/browse.php?form_cat=237">Web Environment</A><BR>
<LI>Intended Audience: <A href="http://cosoft.org.cn/html/osl/browse.php?form_cat=2">End Users/Desktop</A><BR>
<LI>License: <A href="http://cosoft.org.cn/html/osl/browse.php?form_cat=15">GNU General Public License (GPL)</A><BR>
<LI>Operating System: <A href="http://cosoft.org.cn/html/osl/browse.php?form_cat=200">POSIX</A><BR>
<LI>Programming Language: <A href="http://cosoft.org.cn/html/osl/browse.php?form_cat=183">PHP</A><BR>
<LI>Topic: <A href="http://cosoft.org.cn/html/osl/browse.php?form_cat=27">Conferencing</A></LI></UL></TD></TR></TBODY></TABLE></FONT><BR></FONT><BR><BR><STRONG>我安装时候的问题</STRONG></FONT><BR><BR><STRONG>Fatal error</STRONG>: Cannot redeclare gettext()<BR><BR><BR><FONT color=#9acd32 size=5>baidu</FONT>到的,<A href="http://www.crisper.org/plog/index.php?op=printView&amp;articleId=48&amp;blogId=1" target=_blank><FONT color=#ff0000><STRONG>原文</STRONG></FONT></A>不见了～～</P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">尝试安装phpwiki，下边的是我的步骤。<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>修改config/config.ini，可以以config-default.ini为蓝本，以config-dist.ini里的注释作为参考。<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>设置DEBUG</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">，可以在页面下方显示xhtml和css的标示以及页面加载时间；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>设置WIKI_NAME</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">CrisperWiki，之后，可以将自己的logo和signature命名为CrisperWikiLogo.png和CrisperWikiSignature.png，放到theme/default/images下。参见lib/interwiki.map的例子来进行命名；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>设置ADMIN_USER和ADMIN_PASSWD，可以用passencrypt.php来加密密码，如果加密了密码，那么一定要设置ENCRYPTED_PASSWD&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;true；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>如果不想生成访问日志，那就设置ACCESS_LOG&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>设置DATABASE_TYPE&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;SQL，如果想使用PEAR&nbsp;DB&nbsp;lib来访问某种SQL数据库；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>设置DATABASE_PREFIX&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;phpwiki_；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>如果使用mysql数据库，那么将这一行：mysql://user:password@host/databasename设置好，替换这一行中的对应部分：DATABASE_DSN&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">mysql://guest@unix(/var/lib/mysql/mysql.sock)/test</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>如果使用SQL数据库，那就将这两行注释掉：DATABASE_DIRECTORY&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;/tmp和DATABASE_DBA_HANDLER&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;gdbm；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>如果不想让任何一个人查看wiki页面，将ALLOW_ANON_USER，ALLOW_ANON_EDIT和ALLOW_BOGO_LOGIN设置成false，设置ALLOW_USER_PASSWORDS&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;true；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>设置USER_AUTH_ORDER&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Db</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">将使用数据库来进行用户认证；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>设置PASSWORD_LENGTH_MINIMUM&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;4来保证密码至少四位长；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>由于设置USER_AUTH_POLICY&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;old将使用所有可能的方法来进行用户认证，会比较慢，所以设置USER_AUTH_POLICY&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;first-only来确保只使用第一种方法，也就是数据库的方法；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>由于不使用其他认证（LDAP，IMAP，POP3，File，），所以将所有其他的认证的选项全部注释掉；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>设置AUTH_SESS_USER&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;userid，这是已认证用户的sessionid；设置AUTH_SESS_LEVEL&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">，保证使用带密码的认证方式；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>设置GROUP_METHOD&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;DB，将从数据库中读取用户组信息；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>将DBAUTH_AUTH_CHECK，DBAUTH_AUTH_CRYPT_METHOD和DBAUTH_AUTH_USER_EXISTS设置好，我都是直接用的default值，用plain的密码；同时把DBAUTH_AUTH_UPDATE也设置好；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>将DBAUTH_PREF_SELECT设置为使用pref表，这样就能从专门的表中取得用户的preference；同时把DBAUTH_PREF_UPDATE也设置好；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>设置group和user的对应关系，我用的是1:n的关系，去掉only&nbsp;one&nbsp;group&nbsp;per&nbsp;user&nbsp;(</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">:n)后面三行的注释；<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>设置完成之后，试图运行，却发现无论如何用SQL方式的数据库就是无法连接，暂时不知道原因，最后用dbm的方式，使wiki运行起来了（配置文件的相应地方要做修改）。但是却发现对中文的支持很差……于是放弃。<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV>
<P><IMG height=20 src="http://www.blogjava.net/Emoticons/QQ/16.gif" width=20 border=0><BR><BR>引用页 <A href="http://prdownloads.sourceforge.net/phpwiki/phpwiki-1.3.11p1.tar.gz?use_mirror=mesh">http://prdownloads.sourceforge.net/phpwiki/</A><BR>&nbsp;</P><img src ="http://www.blogjava.net/bluesky/aggbug/25497.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2005-12-26 21:28 <a href="http://www.blogjava.net/bluesky/archive/2005/12/26/25497.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>想用wordpress的Permalink,但是空间不支持mod_rewrite,连index.php也不行~~</title><link>http://www.blogjava.net/bluesky/archive/2005/12/26/25453.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Mon, 26 Dec 2005 08:09:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2005/12/26/25453.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/25453.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2005/12/26/25453.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/25453.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/25453.html</trackback:ping><description><![CDATA[想用wordpress的Permalink,但是空间(万网滴)不支持mod_rewrite,连index.php也不行~~<BR>用了index.php/%year%/%monthnum%/%day%/%postname%/<BR>访问不会出错但是不会跳转到正常的页面,所以我想了个方法<BR><BR>理论上的代码,还没有实现<IMG height=19 src="http://www.blogjava.net/Emoticons/71_71.gif" width=19 border=0><BR><BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&lt;?</SPAN><SPAN style="COLOR: #000000">php<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">#</SPAN><SPAN style="COLOR: #008000">$base_uri&nbsp;=&nbsp;index.php/page/welcome.html&nbsp;页面标志&nbsp;=&nbsp;page</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#</SPAN><SPAN style="COLOR: #008000">$base_uri&nbsp;=&nbsp;index.php/entity/2005/12/25/4.index.html&nbsp;页面标志&nbsp;=&nbsp;entity</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#</SPAN><SPAN style="COLOR: #008000">$base_uri&nbsp;=&nbsp;index.php/catalog/wordpress.html&nbsp;页面标志&nbsp;=&nbsp;catalog</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$base_uri</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">$_SERVER</SPAN><SPAN style="COLOR: #000000">[</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">REQUEST_URI</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">];<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">#</SPAN><SPAN style="COLOR: #008000">通过硬面码字符串处理得到下边两个值</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$remark</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">拿到页面的标志参数</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #800080">$id</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">拿到参数值</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #800080">$remark</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">page</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">){<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">include</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">index.php?page=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #800080">$id</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>}</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #800080">$remark</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">category</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">){<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">include</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">index.php?catalog=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #800080">$id</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>}</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #800080">$remak</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">entity</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">){<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">include</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">index.php?p=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #800080">$id</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">?&gt;</SPAN></DIV><BR><img src ="http://www.blogjava.net/bluesky/aggbug/25453.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2005-12-26 16:09 <a href="http://www.blogjava.net/bluesky/archive/2005/12/26/25453.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP获取当前url的函数[终于让我找到了]</title><link>http://www.blogjava.net/bluesky/archive/2005/12/26/25421.html</link><dc:creator>bluesky</dc:creator><author>bluesky</author><pubDate>Mon, 26 Dec 2005 04:59:00 GMT</pubDate><guid>http://www.blogjava.net/bluesky/archive/2005/12/26/25421.html</guid><wfw:comment>http://www.blogjava.net/bluesky/comments/25421.html</wfw:comment><comments>http://www.blogjava.net/bluesky/archive/2005/12/26/25421.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/bluesky/comments/commentRss/25421.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/bluesky/services/trackbacks/25421.html</trackback:ping><description><![CDATA[原文地址<BR><BR><A href="http://blog.chinaunix.net/article.php?articleId=36512&amp;blogId=1184">http://blog.chinaunix.net/article.php?articleId=36512&amp;blogId=1184</A><BR><BR><BR>
<TABLE cellSpacing=0 cellPadding=0 width="95%" border=0>
<TBODY>
<TR>
<TD align=middle width="100%">
<H2><B>[php]预定义变量(一) $_SERVER (附：获取当前URL地址例子)</B></H2></TD></TR>
<TR>
<TD width="100%">
<H2 class=sect2><FONT size=2>例：&nbsp; 我需要 获取当前的 的URL&nbsp; 地址 </FONT></H2>
<P><FONT size=2>$url_this =&nbsp; "</FONT><A href="http:///" .$_server?=""><FONT color=#336699 size=2>http://".$_SERVER</FONT></A><FONT size=2> ['HTTP_HOST'].$_SERVER['PHP_SELF'];<BR>echo $url_this;</FONT></P>
<P><BR><FONT size=2>则显示 ：&nbsp;&nbsp; </FONT><A href="http://localhost/lu.php"><FONT color=#336699 size=2>http://localhost/lu.php</FONT></A></P>
<P><FONT color=#336699></FONT>
<H2 class=sect2><FONT size=2>服务器变量：$_SERVER</FONT></H2>
<P><FONT size=2>注: 在 PHP 4.1.0 及以后版本使用。之前的版本，使用 $HTTP_SERVER_VARS。 </FONT></P>
<P><FONT size=2>$_SERVER 是一个包含诸如头部(headers)、路径(paths)和脚本位置(script locations)的数组。数组的实体由 web 服务器创建。不能保证所有的服务器都能产生所有的信息；服务器可能忽略了一些信息，或者产生了一些未在下面列出的新的信息。这意味着，大量的这些变量在 CGI 1.1 specification 中说明，所以您应该仔细研究它。 </FONT></P>
<P><FONT size=2>这是一个“superglobal”，或者可以描述为自动全局变量。这只不过意味这它在所有的脚本中都有效。在函数或方法中您不需要使用 global $_SERVER; 访问它，就如同使用 $HTTP_SERVER_VARS 一样。 </FONT></P>
<P><FONT size=2>$HTTP_SERVER_VARS 包含着同样的信息，但是不是一个自动全局变量。（注意： $HTTP_SERVER_VARS 和 $_SERVER 是不同的变量，PHP 处理它们的方式不同。） </FONT></P>
<P><FONT size=2>如果设置了 register_globals 指令，这些变量也在所有脚本中可用；也就是，分离了 $_SERVER 和 $HTTP_SERVER_VARS 数组。相关信息，请参阅安全的相关章节 使用 Register Globals。这些单独的全局变量不是自动全局变量。 </FONT></P>
<P><FONT size=2>您或许会发现下面列出的某些 $_SERVER 元素并不可用。注意，如果以命令行方式运行 PHP，下面列出的元素几乎没有有效的（或是没有任何实际意义的）。 </FONT></P>
<P><FONT size=2></FONT></P>
<P><FONT size=2>“PHP_SELF”<BR>当前正在执行脚本的文件名，与 document root相关。举例来说，在URL地址为 </FONT><A href="http://example.com/test.php/foo.bar"><FONT color=#336699 size=2>http://example.com/test.php/foo.bar</FONT></A><FONT size=2> 的脚本中使用 $_SERVER['PHP_SELF'] 将会得到 /test.php/foo.bar 这个结果。 </FONT></P>
<P><FONT size=2>如果 PHP 以命令行方式运行，该变量无效。 </FONT></P>
<P><FONT size=2>“argv”<BR>传递给该脚本的参数。当脚本运行在命令行方式时，argv 变量传递给程序 C 语言样式的命令行参数。当调用 GET 方法时，该变量包含请求的数据。 </FONT></P>
<P><FONT size=2>“argc”<BR>包含传递给程序的命令行参数的个数（如果运行在命令行模式）。 </FONT></P>
<P><FONT size=2>“GATEWAY_INTERFACE”<BR>服务器使用的 CGI 规范的版本。例如，“CGI/1.1”。 </FONT></P>
<P><FONT size=2>'SERVER_NAME'<BR>当前运行脚本所在服务器主机的名称。如果该脚本运行在一个虚拟主机上，该名称是由那个虚拟主机所设置的值决定。 </FONT></P>
<P><FONT size=2>'SERVER_SOFTWARE'<BR>服务器标识的字串，在响应请求时的头部中给出。 </FONT></P>
<P><FONT size=2>“SERVER_PROTOCOL”<BR>请求页面时通信协议的名称和版本。例如，“HTTP/1.0”。 </FONT></P>
<P><FONT size=2>“REQUEST_METHOD”<BR>访问页面时的请求方法。例如：“GET”、“HEAD”，“POST”，“PUT”。 </FONT></P>
<P><FONT size=2>“QUERY_STRING”<BR>查询(query)的字符串。 </FONT></P>
<P><FONT size=2>“DOCUMENT_ROOT”<BR>当前运行脚本所在的文档根目录。在服务器配置文件中定义。 </FONT></P>
<P><FONT size=2>“HTTP_ACCEPT”<BR>当前请求的 Accept: 头部的内容。 </FONT></P>
<P><FONT size=2>“HTTP_ACCEPT_CHARSET”<BR>当前请求的 Accept-Charset: 头部的内容。例如：“iso-8859-1,*,utf-8”。 </FONT></P>
<P><FONT size=2>“HTTP_ACCEPT_ENCODING”<BR>当前请求的 Accept-Encoding: 头部的内容。例如：“gzip”。 </FONT></P>
<P><FONT size=2>“HTTP_ACCEPT_LANGUAGE”<BR>当前请求的 Accept-Language: 头部的内容。例如：“en”。 </FONT></P>
<P><FONT size=2>“HTTP_CONNECTION”<BR>当前请求的 Connection: 头部的内容。例如：“Keep-Alive”。 </FONT></P>
<P><FONT size=2>“HTTP_HOST”<BR>当前请求的 Host: 头部的内容。 </FONT></P>
<P><FONT size=2>“HTTP_REFERER”<BR>链接到当前页面的前一页面的 URL 地址。不是所有的用户代理（浏览器）都会设置这个变量，而且有的还可以手工修改 HTTP_REFERER。因此，这个变量不总是正确真实的。 </FONT></P>
<P><FONT size=2>“HTTP_USER_AGENT”<BR>当前请求的 User_Agent: 头部的内容。该字符串表明了访问该页面的用户代理的信息。一个典型的例子是：Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)。您也可以使用 get_browser() 得到这个信息。 </FONT></P>
<P><FONT size=2>“REMOTE_ADDR”<BR>正在浏览当前页面用户的 IP 地址。 </FONT></P>
<P><FONT size=2>'REMOTE_HOST'<BR>正在浏览当前页面用户的主机名。反向域名解析基于该用户的 REMOTE_ADDR。 </FONT></P>
<P><FONT size=2>注: 必须配置 Web 服务器来建立此变量。例如 Apache 需要在 httpd.conf 中有 HostnameLookups On。参见 gethostbyaddr()。 </FONT></P>
<P><FONT size=2>“REMOTE_PORT”<BR>用户连接到服务器时所使用的端口。 </FONT></P>
<P><FONT size=2>“SCRIPT_FILENAME”<BR>当前执行脚本的绝对路径名。 </FONT></P>
<P><FONT size=2>“SERVER_ADMIN”<BR>该值指明了 Apache 服务器配置文件中的 SERVER_ADMIN 参数。如果脚本运行在一个虚拟主机上，则该值是那个虚拟主机的值。 </FONT></P>
<P><FONT size=2>“SERVER_PORT”<BR>服务器所使用的端口。默认为“80”。如果你使用 SSL 安全连接，则这个值为您所设置的 HTTP 端口。 </FONT></P>
<P><FONT size=2>“SERVER_SIGNATURE”<BR>包含服务器版本和虚拟主机名的字符串。 </FONT></P>
<P><FONT size=2>“PATH_TRANSLATED”<BR>当前脚本所在文件系统（不是文档根目录）的基本路径。这是在服务器进行虚拟到真实路径的映像后的结果。 </FONT></P>
<P><FONT size=2>“SCRIPT_NAME”<BR>包含当前脚本的路径。这在页面需要指向自己时非常有用。 </FONT></P>
<P><FONT size=2>“REQUEST_URI”<BR>访问此页面所需的 URI。例如，“/index.html”。 </FONT></P>
<P><FONT size=2>“PHP_AUTH_USER”<BR>当 PHP 运行在 Apache 模块方式下，并且正在使用 HTTP 认证功能，这个变量便是用户输入的用户名。 </FONT></P>
<P><FONT size=2>“PHP_AUTH_PW”<BR>当 PHP 运行在 Apache 模块方式下，并且正在使用 HTTP 认证功能，这个变量便是用户输入的密码。 </FONT></P>
<P><FONT size=2>“AUTH_TYPE”<BR>当 PHP 运行在 Apache 模块方式下，并且正在使用 HTTP 认证功能，这个变量便是认证的类型。</FONT></P></TD></TR></TBODY></TABLE><img src ="http://www.blogjava.net/bluesky/aggbug/25421.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/bluesky/" target="_blank">bluesky</a> 2005-12-26 12:59 <a href="http://www.blogjava.net/bluesky/archive/2005/12/26/25421.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>