<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title><![CDATA[追随我心]]></title> 
<description><![CDATA[反对权威,反对一切僵硬教育和无声忍让.喜欢聪明人,追逐完美的产品,自由的气氛!]]></description>
<link>http://hit9.hit9.net/</link>
<language>zh-cn</language>
<generator>www.emlog.net</generator>
<item>
	<title>python字符串切片巧妙的方法</title>
	<link>http://hit9.hit9.net/post-161.html</link>
	<description><![CDATA[<p>看到一个博文这么讲的,如醍醐灌顶.</p>
<p>博文链接:<a href="http://euyuil.com/2143/note-about-python-string-slicing/">http://euyuil.com/2143/note-about-python-string-slicing/</a></p>
<p>比如字符串式hello这个单词:</p>
<p>&nbsp;</p>
<pre class="brush:python; toolbar: true; auto-links: true;">word='hello';
print word[2]#l
print word[1:3]#el
print word[1:]#ello
print word[:3]#hel
print word[:]#hello
print word[-1]#o
print word[-0]#h
print word[-1:]#o
print word[-1:0]#''
print word[-1:3]#''</pre> 博文中指出,可以把字符串的各个字符之间的间隙作标号:<br />
<p><a target="_blank" href="/content/uploadfile/201205/addf4466973cb14e774edffb8ca3106920120512085710.png" id="ematt:12"><img src="/content/uploadfile/201205/addf4466973cb14e774edffb8ca3106920120512085710.png" alt="点击查看原图" border="0" /></a></p>
<p>对于一个数字的word[n],当然跟数组操作一样,起始位置0</p>
<p>对于片段截取,比如word[1:3] 从间隙下标1数到间隙下标3,取其之间的字符串即可.</p>
<p>对于word[:3]和[1:]这样的,未给出具体数字,视作取极端,就是使字符串尽可能的大,比如 word[:]取出了整个字符串</p>
<p>对于取不出的,返回空字符串''</p>]]></description>
	<pubDate>Sat, 12 May 2012 08:27:52 +0000</pubDate>
	<author>hit9</author>
	<guid>http://hit9.hit9.net/post-161.html</guid>

</item>
<item>
	<title>Ruby or Python</title>
	<link>http://hit9.hit9.net/post-160.html</link>
	<description><![CDATA[<p>我决定学习一门通用型语言作为自己的主要使用语言.当然我并不抛弃php,可是说不定呢,也许当我学习完python或者ruby后就再也不动php了.</p>
<p>在这之前我对python还是ruby的取舍问题犹豫了很久.听学长说,还有我的老师说,ruby(尤其是rails)这两年很火,貌似ruby有说不完的好处.我也去知乎上看了看大家的议论.</p>
<p>最近还比较流行的是函数式编程,我觉得这个更偏向于逻辑运算部分,其实编程更靠近函数,靠近数学的话,我就更喜欢,里面就有更多的乐趣和逻辑道理.python的函数式特性比ruby更强些.</p>
<p>ruby的哲学是编程为了fun.那样造成ruby简直太灵活了,条条大路通罗马,这样使我感到不安全和恐慌,因为潜意识里觉得,越灵活多变的东西,性能和规范性都欠佳.而python的性能似乎比ruby高些.毕竟python经受了许多大型网站的考验.python里面是达到一个目的只有一个方法,而ruby是多种.我喜欢大的思维方式是多种(比如排序的算法多种多样),而不喜欢仅仅打印一个hello world就出那么多花样.多样性的存在更多的是服务于不同的需求,根据需求我们从不同的方案中做取舍.</p>
<p>就像,我更喜欢标准的c而不喜欢c++一样.</p>
<p>好了,不罗嗦了,</p>
<p>&nbsp;</p>]]></description>
	<pubDate>Sat, 12 May 2012 08:08:36 +0000</pubDate>
	<author>hit9</author>
	<guid>http://hit9.hit9.net/post-160.html</guid>

</item>
<item>
	<title>PHP 安全指南</title>
	<link>http://hit9.hit9.net/post-159.html</link>
	<description><![CDATA[收藏一个<a href="http://hhacker.com/files/200709/1/index.html" target="_blank">http://hhacker.com/files/200709/1/index.html</a>]]></description>
	<pubDate>Sat, 12 May 2012 06:55:48 +0000</pubDate>
	<author>hit9</author>
	<guid>http://hit9.hit9.net/post-159.html</guid>

</item>
<item>
	<title>一道php面试题</title>
	<link>http://hit9.hit9.net/post-158.html</link>
	<description><![CDATA[<pre class="brush:php; toolbar: true; auto-links: true;">&lt;?php
echo '24aaa'+6;</pre>显示30]]></description>
	<pubDate>Sat, 12 May 2012 06:11:48 +0000</pubDate>
	<author>hit9</author>
	<guid>http://hit9.hit9.net/post-158.html</guid>

</item>
<item>
	<title>PHP重载动态设置非公开属性</title>
	<link>http://hit9.hit9.net/post-157.html</link>
	<description><![CDATA[<p>PHP中提供了魔术方法__set(),和__call()来设置非公开属性和未定义的方法</p>
<p>1.运行中遇到类中未定义的属性就运行__set()函数</p>
<p>2.运行中遇到类未定义的方法就运行 __call()函数</p>
<pre class="brush:php; toolbar: true; auto-links: true;">&lt;?php
class test	
{
	private $data;
	function __construct()
	{
		$this-&gt;data=array();
	}
	function __set($name,$var)
	{
		$this-&gt;data[$name]=$var;
	}
}

$test=new test;
$test-&gt;age=19;
print_r($test);
?&gt;</pre><pre class="brush:php; toolbar: true; auto-links: true;"></pre><p><b> 打印结果:</b></p>
<p><a target="_blank" href="/content/uploadfile/201205/552f7dc0f40345703827c3b7e3f0131320120507224341.png" id="ematt:11"><img src="/content/uploadfile/201205/552f7dc0f40345703827c3b7e3f0131320120507224341.png" alt="点击查看原图" border="0" /></a> </p>
 利用这个特点,可以实现一个对象的数据的变化,我们在构造连贯的CURD操作的时候,可以利用这个特点<b>把数据和查询条件缓存到对象的这个数组data中,最后再构造sql语句来查询数据库.</b>]]></description>
	<pubDate>Mon, 07 May 2012 22:36:02 +0000</pubDate>
	<author>hit9</author>
	<guid>http://hit9.hit9.net/post-157.html</guid>

</item>
<item>
	<title>PHP中如果类与一个方法重名会怎么样</title>
	<link>http://hit9.hit9.net/post-156.html</link>
	<description><![CDATA[<pre class="brush:php; toolbar: true; auto-links: true;">&lt;?php
/**
 * 
 **/
class test
{
	function test()
	{
		echo '1';
	}	
}

$test=new test;
$test-&gt;test();
?&gt;</pre><p>看上面的代码.</p>
<p>输出结果:11</p>
<p>可是为什么呢??</p>
<p>因为与类同名的那个函数被视为了构造函数</p>]]></description>
	<pubDate>Mon, 07 May 2012 18:27:22 +0000</pubDate>
	<author>hit9</author>
	<guid>http://hit9.hit9.net/post-156.html</guid>

</item>
<item>
	<title>PHP 数组入栈的操作方法</title>
	<link>http://hit9.hit9.net/post-155.html</link>
	<description><![CDATA[<p>再一次亮瞎我的眼!</p>
<p>请看以下两段代码:</p>
<p><pre class="brush:php; toolbar: true; auto-links: true;">&lt;?php
$arr=array();
for ($i = 0; $i &lt; 10; $i++) {
	array_push($arr,$i);
}
print_r($arr);
?&gt;</pre><pre class="brush:php; toolbar: true; auto-links: true;">&lt;?php
$arr=array();
for ($i = 0; $i &lt; 10; $i++) {
	$arr[]=$i;
}
print_r($arr);
?&gt;</pre>两个脚本都实现了一个相同的功能,就是入栈,扩充数组的功能.</p>
<p>php竟然还能这样!在C中是不允许的!.</p>
<p>另外str有类似的.=操作</p>]]></description>
	<pubDate>Mon, 07 May 2012 17:38:02 +0000</pubDate>
	<author>hit9</author>
	<guid>http://hit9.hit9.net/post-155.html</guid>

</item>
<item>
	<title>细节:PHP连接mysql的函数,mysql_connect()与mysql_pconnect()</title>
	<link>http://hit9.hit9.net/post-154.html</link>
	<description><![CDATA[<p><b>1.mysql_connect()建立一个短连接,而pconnect建立一个长连接.</b></p>
<p><b>2.连接复用:</b></p>
<p>&nbsp; &nbsp; mysql_connect():打开或重复使用一个到 MySQL 服务器的连接。</p>
<p>&nbsp; &nbsp;mysql_pconnect():首先，当连接的时候本函数将先尝试寻找一个在同一个主机上用同样的用户名和密码已经打开的（持久）连接，如果找到，则返回此连接标识而不打开新连接。

其次，当脚本执行完毕后到 SQL 服务器的连接不会被关闭，此连接将保持打开以备以后使用（mysql_close() 不会关闭由 mysql_pconnect() 建立的连接）。</p>
<p>&nbsp;</p>
<p><b>可以说两个函数都会进行连接复用,但pconnect是持久连接,线程结束后并不关闭</b></p>
<p><b><br />
</b></p>
<p>在Apache服务器环境下,php是以模块方式运行的.而cgi方式下,connect这个短连接也会占用一个进程.(cgi方式下每一个php访问起一个进程),所以cgi方式这两个函数没什么区别的.apache 下的话,并发不高的时候短连接更快.</p>
<p>&nbsp;</p>
<p>总之,在数据库操作(如果不考虑PDO,mysqli等),使用单例,加__desruct close的方式操作数据库.</p>
<p>在PHP层面上这个优化没多少作用</p>]]></description>
	<pubDate>Mon, 07 May 2012 14:33:20 +0000</pubDate>
	<author>hit9</author>
	<guid>http://hit9.hit9.net/post-154.html</guid>

</item>
<item>
	<title>php工厂模式</title>
	<link>http://hit9.hit9.net/post-153.html</link>
	<description><![CDATA[<span style="font-weight:bold;">所谓工厂模式,构造一个类似工厂的类用来根据不同需求生产不同的类的实例,并返回这个实例给系统.</span><br style="font-weight:bold;" />
同常用在需要根据不同情况分流进行实例化的时候<br />
IHello.php的代码:<br />
<pre class="brush:php; toolbar: true; auto-links: true;">&lt;?php
/*
 *接口
 */
interface IHello{
	function sayHello();
}</pre><br />
<pre class="brush:php; toolbar: true; auto-links: true;">&lt;?php
require_once('IHello.php');
/**
 * 具体的类,被选择,继承接口IHello,即所谓的工厂生产的产品
 **/
class Hello1 implements IHello
{
	function sayHello()
	{
		echo 'This is Hello1';
	}
}

class Hello2 implements IHello
{
	function sayHello()
	{
		echo 'This is Hello2';
	}
}
/**
 * 类Hello,这个类就是所谓的工厂,根据需求生产不同的类的实例
 **/		
class Hello
{
	static public function Create($flag)	
	{
		if($flag==0)
		{
			return new Hello1;
		}elseif($flag==1)
		{
			return new Hello2;
		}else{
			die();
		}
	}
}

//以下是测试,Hello这个类工厂根据参数来构造新的类
echo Hello::Create(0)-&gt;sayHello();
echo Hello::Create(1)-&gt;sayHello();</pre><br />]]></description>
	<pubDate>Thu, 03 May 2012 09:32:03 +0000</pubDate>
	<author>hit9</author>
	<guid>http://hit9.hit9.net/post-153.html</guid>

</item>
<item>
	<title>PHP单例模式</title>
	<link>http://hit9.hit9.net/post-152.html</link>
	<description><![CDATA[<span style="font-weight:bold;">单例模式:程序运行一次包含且仅一个实例.</span><br />
<span style="font-family:'courier new',courier;font-size:10pt;">单例模式确保某一个类只有一个实例，而且自行实例化并向整个系统提供这个实例,这个类称为单例类<br />
通常的应用:数据库连接等独占资源<br />
<span style="font-weight:bold;">一般设计一个单例类需要满足如下要求:</span><br />
<span style="background-color:#ffffff;color:#e53333;">1.类中存在一个私有的静态变量</span><br />
<span style="background-color:#ffffff;color:#e53333;"> </span><span style="background-color:#ffffff;color:#e53333;"> 2.类中必须有一个静态的公共函数</span><br />
<span style="background-color:#ffffff;color:#e53333;"> </span><span style="background-color:#ffffff;color:#e53333;"> 3.类不能被实例化(构造函数须是私有的</span><span style="color:#e53333;">)</span><br />
<pre class="brush:php; toolbar: true; auto-links: true;">&lt;?php
/*
 *测试数据库连接的单例模式
 */
/**
 * 单例模式连接数据库
 **/
class DB
{
	private static $db=NULL;	
	private	function __construct()
	{
		;
	}
	public static function conn()
	{
		if(self::$db==NULL)	
		{
			self::$db=mysql_connect('localhost','root','****');
		}
		return self::$db;
	}
}
echo DB::conn();
echo DB::conn();
?&gt;</pre><br />
</span>]]></description>
	<pubDate>Thu, 03 May 2012 08:31:50 +0000</pubDate>
	<author>hit9</author>
	<guid>http://hit9.hit9.net/post-152.html</guid>

</item></channel>
</rss>
