<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
   <title>阮一峰的IT笔记</title>
   <link rel="alternate" type="text/html" href="http://www.ruanyifeng.com/notes/" />
   
   <id>tag:www.ruanyifeng.com,2009:/notes//4</id>
   <updated>2008-06-05T20:05:57Z</updated>
   
   <generator uri="http://www.sixapart.com/movabletype/">Movable Type 3.33</generator>

<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/ruanyifeng_it" /><feedburner:info uri="ruanyifeng_it" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
   <title>Canon打印机“废弃墨水吸收器已满”的解决办法</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/AuBZCIIsAEo/canon.html" />
   <id>tag:www.ruanyifeng.com,2008:/notes//4.982</id>
   
   <published>2008-05-03T06:43:21Z</published>
   <updated>2008-06-05T20:05:57Z</updated>
   
   <summary>Canon PIXMA iP1000 :Waste Ink Counter Reset Manual for Service mode</summary>
   <author>
      <name />
      
   </author>
         <category term="硬件" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      Canon PIXMA iP1000 :Waste Ink Counter Reset Manual for Service mode

1. Turn off the printer. And disconnect the printer cable.
2. Press and hold the POWER button, turn on the printer.
3. The indicator (L.E.D.) should be green.
4. Press and release the RESUME button , the indicator (L.E.D.) should be orange.
5. Press and release the RESUME button again, the indicator (L.E.D.) should be green.
6. Release both buttons. 

1、按住 电源 键 插上电源线 。

2、按三次 退纸（就是电源键旁边的那个）键，松开电源键，打印机启动 。

3、打开打印机。

==================

佳能ip系列废墨清零工具 

程序适用佳能IP系列机型： 
第一步：关闭打印机电源。并把电源线从电源插卒拔开。 

第二步：按紧打印机的电源键同时插上电源线。(此时机器电源灯亮) 

第三步：不松开电源键。按4下进纸键。电源灯显示：黄--绿--黄---绿。 

第四步：松开电源键。机器启动后，电源灯熄灭。 

第五步：重新开机。机器开机正常。连接电脑，装好打印的驱动程序。 

第六步：打开维修软件。点击GeneralTool图标。出现程序窗口，在usbport项中选择该 
打印机所对应的USB端口。在下面的cleaning 和EPROM项前打勾，点击test 1。打印机 
电源灯闪动一下。机器已清零重新开机即可。

这是清零软件地址：http://www.100gsoft.cn/soft/sort011/sort027/down-1368.html

 

先上这个网站下载了程序，然后按着上面的步骤执行问题就解决了，现在打印也不需再按进纸键了。：）

 

说明：此方法针对于佳能IP1000型号打印机。
      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2008/05/canon.html</feedburner:origLink></entry>
<entry>
   <title>符合标准的固定在网页中固定位置的广告（转贴）</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/hKnETp1CHQ4/post_21.html" />
   <id>tag:www.ruanyifeng.com,2008:/notes//4.979</id>
   
   <published>2008-01-01T06:47:29Z</published>
   <updated>2008-06-01T19:15:13Z</updated>
   
   <summary><![CDATA[符合标准的固定在网页中固定位置的广告，不随滚动条的滚动而滚动。 * { margin:0px; padding:0px; } #main{ width:650px; } #modalwin{ width:100%; height:100%; background-color:red; position:fixed !important; top/**/:0px; position:absolute; z-index:100; top:expression(offsetParent.scrollTop);left:expression(offsetParent.scrollLeft); height:expression(document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight); width:expression(document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth); display:none; } 另外，可以根据情况，加上background-attachment: fixed; background-image: url();这两句CSS。 =============== &lt;style&gt; .aa{height:2000px;width:40px;background:#eee;} .bb{width:50px;height:80px;background:red;float:right; position:fixed...]]></summary>
   <author>
      <name />
      
   </author>
         <category term="css" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      <![CDATA[符合标准的固定在网页中固定位置的广告，不随滚动条的滚动而滚动。

	*	{
		margin:0px;
		padding:0px;
	}

	#main{
		width:650px;
	}

	#modalwin{
		width:100%;
		height:100%;
		background-color:red;
		position:fixed !important; top/**/:0px; 
		position:absolute; z-index:100;
		top:expression(offsetParent.scrollTop);left:expression(offsetParent.scrollLeft); 
		height:expression(document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight);		
		width:expression(document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth);		
		display:none;
	}

另外，可以根据情况，加上background-attachment: fixed; background-image: url();这两句CSS。

===============

&lt;style&gt;  
.aa{height:2000px;width:40px;background:#eee;}   
.bb{width:50px;height:80px;background:red;float:right;   
    position:fixed !important; top/**/:0px;   
    position:absolute; z-index:100; top:expression(offsetParent.scrollTop+20);right:20px;   
&lt;/style&gt;  
  
&lt;div class=&quot;aa&quot;&gt;  
 我是不动的。 
    &lt;script&gt;for(var i=0;i&lt;99;i++){document.write(i+&quot;&lt;br&gt;&quot;);}&lt;/script&gt;  
  
    &lt;div class=&quot;bb&quot;&gt;move&lt;/div&gt;  
  
&lt;/div&gt;]]>
      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2008/01/post_21.html</feedburner:origLink></entry>
<entry>
   <title>PHP: UTF-8兼容的substr()函数</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/uRfrEB1n4WM/php_utf8substr.html" />
   <id>tag:www.ruanyifeng.com,2007:/notes//4.978</id>
   
   <published>2007-12-09T09:55:27Z</published>
   <updated>2007-12-09T17:56:00Z</updated>
   
   <summary> function utf8_substr($str,$start) { /* UTF-8 version of substr(), for people who can't use mb_substr() like me. Length is not the count of Bytes, but the count of UTF-8 Characters Author: Windix Feng Bug report to: windix(AT)gmail.com, http://www.douzi.org - History...</summary>
   <author>
      <name />
      
   </author>
         <category term="PHP" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      <![CDATA[<?
function utf8_substr($str,$start) { 
    /*
    UTF-8 version of substr(), for people who can't use mb_substr() like me.
    Length is not the count of Bytes, but the count of UTF-8 Characters
    
    Author: Windix Feng
    Bug report to: windix(AT)gmail.com, http://www.douzi.org 

    - History -
    1.0 2004-02-01 Initial Version
    2.0 2004-02-01 Use PREG instead of STRCMP and cycles, SPEED UP!
    */ 

preg_match_all("/[x01-x7f]|[xc2-xdf][x80-xbf]|xe0[xa0-xbf][x80-xbf]|[xe1-xef][x80-xbf][x80-xbf]|xf0[x90-xbf][x80-xbf][x80-xbf]|[xf1-xf7][x80-xbf][x80-xbf][x80-xbf]/", $str, $ar);  

    if(func_num_args() >= 3) { 
        $end = func_get_arg(2); 
        return join("",array_slice($ar[0],$start,$end)); 
    } else { 
        return join("",array_slice($ar[0],$start)); 
    }
}
?> ]]>
      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2007/12/php_utf8substr.html</feedburner:origLink></entry>
<entry>
   <title>关于PHP中Object对象的笔记</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/pkCD12-PS6w/phpobject.html" />
   <id>tag:www.ruanyifeng.com,2007:/notes//4.976</id>
   
   <published>2007-11-21T04:41:29Z</published>
   <updated>2007-11-21T15:33:42Z</updated>
   
   <summary>1.

当将所有实例设为null，php会自动清除对象的引用。</summary>
   <author>
      <name />
      
   </author>
         <category term="PHP" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      1.

当将所有实例设为null，php会自动清除对象的引用。

2.

建构子：__construct()

清除对象时自动执行的方法：__destruct()

也可以设置手动清除对象的方法：destroy或者clean_up

3.

对象中的三种变量范围：public、private和protected。

4.

对象中的常量属性可以使用const关键字，然后在对象外部以“对象名::属性名”的格式引用，在对象内部以“self::属性名”的格式引用。

5.

在整个对象所有实例中通用的属性，就是静态属性，使用static关键字。

static与const的区别在于，const前只能使用public关键字，而static可以使用其他关键字。此外，static属性并非只读。

6.

在整个对象所有实例中通用的方法，就是静态方法，也使用static关键字。

7.

可以定义一个抽象类，用来定义界面。这种类只能被继承，而不能创造实例。在类内部，用abstract定义子类必须提供的方法。

凡是有abstract方法的类，必须在类名前使用abstract关键字。

abstract class Producr

8.

在方法前加final关键字，可以防止子类override这个方法。

类名之前也可以加final关键字，这样就表明其他类不能继承它。

9.

界面interface用来定义一系列抽象类的结构。

interface IProduct
{
... ...
}

abstract class Product implements Iproduct
{
......
}

10.

== 比较两个对象是否为同样类型，以及是否有同样的值。
=== 比较两个对象是否为同一个类的实例。

11. 

类的克隆：完全复制值。

$a = new SomeClass();
$b = clone $a;

可以定义一个__clone()函数，专门对克隆行为进行定制。

12.

可以定义一个类的__toString()方法，对使用print和echo函数的行为进行定制。

13.

get_class()函数：返回一个对象的类名。

14.

可以在一个函数的参数前加类名，表示TypeHint。

15.

可以定义一个__autoload()函数，它的参数就是php找不到定义的类名。可以在这个函数中定义如何自动加载。
      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2007/11/phpobject.html</feedburner:origLink></entry>
<entry>
   <title>Error Handling in PHP: Coding Defensively</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/lwsx4OimwHw/error_handling_in_php_coding_d.html" />
   <id>tag:www.ruanyifeng.com,2007:/notes//4.975</id>
   
   <published>2007-11-17T15:32:42Z</published>
   <updated>2007-11-17T23:34:01Z</updated>
   
   <summary>As with any programming language, when you code in PHP, it helps immensely if you set up your applications to handle errors gracefully. This article explores some of the most common error checking methods available in PHP, and provides hands-on examples that use different error handling methods.</summary>
   <author>
      <name />
      
   </author>
         <category term="PHP" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      <![CDATA[Error Handling in PHP: Coding Defensively

Alejandro Gervasio

http://www.devshed.com/c/a/PHP/Error-Handling-in-PHP-Coding-Defensively/

1.

As with any programming language, when you code in PHP, it helps immensely if you set up your applications to handle errors gracefully. This article explores some of the most common error checking methods available in PHP, and provides hands-on examples that use different error handling methods.

Introduction

Getting started with PHP is quite easy. Armed with a good PHP editor, any beginner can create a simple database-driven web application with minor hassles. Moreover, given a little more time, an average developer can pick up a good understanding of object-oriented programming and start working with classes and objects. Definitely, this sounds like a good and exciting thing -- except for when,  during the development of an application, one has to write error handling code.

Let’s be honest. For novice (and not so novice) programmers, coding error handling routines is boring stuff. Even when it’s something that you can’t hide from very often, error manipulation usually is limited to writing a few “die()/exit()” statements when connecting to a database server, and some additional checking lines for handling potential errors within program execution. From a realistic point of view, the things about error handling is that if you’re developing a web application which lacks decent error checking code (due to ignorance or laziness), sooner or later your application will fail ungracefully. The result of this will be possibly the occurrence of potentially harmful errors -- particularly in the area of security -- and the display of ugly messages, making the whole program look very unprofessional.

Since error handling is something that you should introduce (at least progressively) into your applications, in this article I’ll explore some of the most common error checking methods available in PHP, in order to make web applications much more robust and reliable. The end result of this experience will be an illustrative list of hands-on examples that utilize different error handling methods, ranging in from using simple “die()” statements, to manipulating errors within an object-oriented context, by utilizing exceptions.

Having drawn the general guidelines for this tutorial, it’s time to dive into the topic and turn error handling into an instructive journey. Let’s get started.

2.

The first example that implements the basics of script-level error handling is based on the popular “die()” statement. For this reason, I’ll write a simple PHP class, which reads contents from a data file. In its basic incarnation, this class looks like this:

class FileReader{
  var $file;
  var $fileDir='fileDir/';
  function FileReader($file){
    $this->file=$file;
  }
  function getContent(){
    return file_get_contents("{$this->fileDir}{$this->file}.php");
  }
}

 

As I mentioned earlier, the above class implements a trivial file reader. Aside from the constructor, the class exposes only one public method, “getContent()”, which reads the content from a file passed in as an argument to the constructor. As you can see, the class has been coded with no error checking lines, so any object instantiated from it will cause a non-fatal error if the “$file” parameter doesn’t point to a valid file. The lines below show this circumstance:

// instantiate FileReader object
// pass in invalid file to the constructor
$fr=new FileReader('inexistent_file');
// echo file content
echo $fr->getContent();

Warning: file_get_contents(fileDir/.php): failed to open stream: No such file or directory in /path/to/file/exceptions.php on line 4.

Although the example is rather crude, it demonstrates in a nutshell how a class written without any error handler can be easily broken up. Now, in order to implement a basic error handler, I’m going to include some “die()” statements within the class methods, as follows:

class FileReader{
  var $file;
  var $fileDir='fileDir/';
  function FileReader($file){
    if(!file_exists("{$this->fileDir}{$file}.php")){
      die('File '.$file.' not found');
    }
    $this->file=$file;
  }
  function getContent(){
    if(!$content=file_get_contents("{$this->fileDir}{$this->file}.php")){
      die("Unable to read file contents");
    }
    return $content;
  }
}

 

Now, the class looks subtly better and more efficient. Notice how a couple of “die()” statements allow you to code defensively, and introduce an appreciable difference compared to the earlier version. In this case, if I instantiate a new “file reader” object, by pointing it to an inexistent file, this is what I should get as a result:

// instantiate FileReader object
$fr=new FileReader('inexistent_file');
// echo file content
echo $fr->getContent();

File inexistent_file not found.

As you can see, the above snippet is a little more efficient, because it implements a simple error handling mechanism. Instead of leaving out of control conflictive operations, such as reading file contents, the class is capable at least of stopping program execution if an error occurs. Indeed, this is a considerable improvement from a programming point of view, and certainly didn’t demand any hard work from us.

However, pseudo functions like “die()” statements are rather inflexible. After all, it doesn't always happen that a script must be abruptly terminated. Fortunately, PHP exposes other functions which are more helpful and flexible for handling errors. Considering this, let’s move on and have a look at the PHP built-in “trigger_error()” function, in order to find out how it can be used.

3.

As I explained in earlier examples, the “die()” statement can be used to build in rudimentary error handling mechanisms. But, particularly in mid-sized and large applications, this method isn’t flexible enough. As I said before, PHP provides developers with the “trigger_error()” function, which can be utilized for developing a slightly more sophisticated error handler.

Let’s return to the sample class written earlier, and see how this function can be used for writing defensive code:

class FileReader{
  var $file;
  var $fileDir='fileDir/';
  function FileReader($file){
    if(!file_exists("{$this->fileDir}{$file}.php")){
      trigger_error('File '.$file.' not found',E_USER_WARNING);
    }
    $this->file=$file;
  }
  function getContent(){
    if(!$content=file_get_contents("{$this->fileDir}{$this->file}.php")){
      trigger_error("Unable to read file contents",E_USER_WARNING);
    }
    return $content;
  }
}

As seen above, I’ve included a couple of “trigger_error()” functions, right at the places where the class could raise potential errors. According to this rewritten class, a file reader object might be instantiated like this:

// instantiate FileReader object
$fr=new FileReader('inexistent_file');
// echo file content
echo $fr->getContent();

And the resulting output would be as follows:

Notice: File inexistent_file not found in path/to/file
Warning: file_get_contents(fileDir/inexistent_file.php): failed to open stream: No such file or directory in path/to/file
Notice: Unable to read file contents in path/to/file

In this case, the “trigger_error()” function will display some notices and warnings when a specific error has occurred, but in all cases the execution of the program won’t be stopped, since I passed into the function a non-fatal error flag (E_USER_WARNING). As you may have guessed, this error mechanism isn’t very useful when used alone. After all, what’s the point of having a bunch of non-fatal errors, if they’re not processed in a more helpful way?

The real power of the “trigger_error()” function is unleashed when used in conjunction with the “set_error_handler()” function. As you probably know, this function allows us to specify the name of an error handling function, and whenever an error is triggered, program flow will be moved to the specified function.

Certainly, the “trigger_error()/set_error_handler()” combination is very handy for delegating error handling toward a delineated section within an application. To demonstrate its functionality, I’ll rewrite the sample class, this time by specifying a callback function for “set_error_handler()”. Take a look:

class FileReader{
  var $file;
  var $fileDir='fileDir/';
  function FileReader($file){
    if(!file_exists("{$this->fileDir}{$file}.php")){
      trigger_error('File '.$file.' not found',E_USER_WARNING);
    }
    $this->file=$file;
  }
  function getContent(){
    if(!$content=file_get_contents("{$this->fileDir}{$this->file}.php")){
      trigger_error("Unable to read file contents",E_USER_WARNING);
    }
    return $content;
  }
}
// define error handling function

function fileErrorHandler($errnum,$errmsg,$file,$lineno){
  if($errnum==E_USER_WARNING){
    echo 'Error: '.$errmsg.'<br />File: '.$file.'<br />Line: '.$lineno;
    exit();
  }
}

As shown above, I’ve defined the “fileErrorHandler()” function, in order to trap raised errors, and incidentally obtain more specific information about the error that occurred. In this example, the function has been written to display only information on E_USER_WARNING errors, by displaying the message passed in through each “trigger_error()” function, along with the filename and line number at which the error originally occurred. With such a useful error handler, let’s see the output for the improved version of the sample script:

// define error handling function
set_error_handler('fileErrorHandler');
// instantiate FileReader object
$fr=new FileReader('inexistent_file');
// echo file content
echo $fr->getContent();

Error: File inexistent_file not found
File: path/to/file/exception.php
Line: 6

Now, things are more interesting. Notice how program flow was transferred to the “fileErrorHandler()” function, when the first “trigger_error()” function raised an error condition. Additionally, I received slightly more detailed information on the error itself, since the script's output included the type of error, file and line number where the error took place. This alone gives us a considerable improvement on setting up error handlers, because by defining a callback function, it’s possible to build in a centralized error handling mechanism and liberate application code from manipulating potentially conflictive conditions.

In most cases, the “trigger_error()”/set_error_handler()” combination can be successfully implemented, in order to work either with procedural programs or with object-based applications. Particularly in object-oriented environments, one common approach consists of developing a class (or a set of classes), which are responsible for handling all the errors raised during the execution of an program.

So, taking into account that object-based error manipulation is relevant during the development of an application, it’s worthwhile to take a brief look at the popular PEAR error object, so you can have a clear idea of how it works with the previous “FileReader” class.

4.

In PHP 4 object-oriented scenarios, one of the most popular approaches for handling errors is the PEAR_Error object. While not all developers feel comfortable working with PEAR packages, admittedly it’s a very strong framework that can be used in numerous applications. Specifically, the PEAR_Error object is extremely useful for handling errors, and certainly provides a lot of information that you might need. Let’s have a look at its methods:

- PEAR::getMessage(): returns the error message.
- PEAR::getType(): returns the PEAR_Error subtype.
- PEAR::getUserInfo(): returns additional information on the error and the context where it took place
- PEAR::getCode(): return the error code. Eventually, this method might return no values.

Having described the corresponding object methods, the next step will consist of modifying the sample class, so it can return a PEAR_Error object, instead of using the “trigger_error()” function:

// include PEAR library
require_once("PEAR.php");

class FileReader{
  var $file;
  var $fileDir='fileDir/';
  function FileReader($file){
    if(!file_exists("{$this->fileDir}{$file}.php")){
      return PEAR::RaiseError('File '.$file. ' not found');
    }
    $this->file=$file;
  }
  function getContent(){
    if(!$content=file_get_contents("{$this->fileDir}{$this->file}.php")){
      return PEAR::RaiseError('Unable to read file contents');
    }
    return $content;
  }
}

As you can see, now the above class returns a PEAR_Error object when things go wrong. Given the existence of this object, I’m able to call one of its methods, as follows:


$fr=new FileReader('inexistent_file');
echo $fr->getContent();
if (PEAR::isError($fr)) {
    echo $fr->getMessage()."\n";
    exit();
}

The above example demonstrates how to check for the existence of an error object, and accordingly call its “getMessage()” method. Evidently, this method provides much more flexibility and allows you to obtain specific information on both the nature of the error and the context in which it took place.

Of course, this is only a introductory example, so if you feel curious about PEAR, visit its site (http://pear.php.net/) and browse the numerous packages available for downloading.

Having scratched the surface of PEAR_Error objects, let’s leap forward and analyze the last method for handling program failures, in this case by utilizing Boolean flags.

5.

The last error handling method we'll review here is perhaps the most ancient. Boolean flags have been used from the very beginning of many programming languages, and PHP isn’t an exception. While they’re quite easy to implement, the major drawback is that they’re not very informative about the error that occurred and its context. Here’s a crude (and rather inefficient) implementation of the “FileReader” class, which uses Boolean flags:

class FileReader{
  var $file;
  var $fileDir='fileDir/';
  function FileReader($file){
    if(!@file_exists("{$this->fileDir}{$file}.php")){
      return false;
    }
    $this->file=$file;
  }
  function getContent(){
    if(!@$content=file_get_contents("{$this->fileDir}{$this->file}.php")){
      return false;
    }
    return $content;
  }
}

Considering the definition for the above example, class errors might be handled as follows:

$fr=new FileReader('inexistent_file');
if(!$fr->getContent()){
  die('Unable to read file contents');
}
else{
  echo $fr->getContent();
}

 

In the example, I’ve deliberately used the “@” error suppression operator, in order to avoid the complaints of the PHP interpreter and return a false value (or 0 or –1) when a failure happens. At first glance, you can see the inefficiency of this method, as well as its limited flexibility. However, this approach has proven to be quite successful in procedural applications, or when client code is capable of handling simple errors without overly polluting the whole application.

At this point, I’ve explored the pros and cons of common error handling approaches in PHP 4. Probably you’ll want to add a few more methods to my generic list, but in general terms, this is what you’ll need to use in most cases. Definitely, in large web applications, a set of error manipulating classes is preferred, so you can handle errors through a centralized point. However, the “trigger_error()/set_error_handler()” combination may suit the needs of small projects, so it’s worth considering.

To wrap up

In this first tutorial, I’ve hopefully covered the most common techniques for handling failures within PHP 4 applications. Over the second (and last part) of this series, I’ll be focusing attention on exceptions in PHP 5. As you’ll see, exceptions provide a powerful mechanism for handling errors through a centralized point, and offer a nice level of information on raised errors and their context. Want to know more? You’ll have to wait for the last part!]]>
      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2007/11/error_handling_in_php_coding_d.html</feedburner:origLink></entry>
<entry>
   <title>一个PHP错误处理范例</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/idzV03GNux4/php_2.html" />
   <id>tag:www.ruanyifeng.com,2007:/notes//4.974</id>
   
   <published>2007-11-17T13:01:36Z</published>
   <updated>2007-11-17T21:08:02Z</updated>
   
   <summary> // Decide what errors to report: error_reporting (E_ERROR | E_WARNING | E_NOTICE); // Webmaster email and error page url: $Wmemail = 'you@ursite.com'; $ErrorPage = 'http://www.ursite.com/error.html'; // This function will check the error type: function MailErrorHandler($errno, $errstr, $errfile='?', $errline= '?')...</summary>
   <author>
      <name />
      
   </author>
         <category term="PHP" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      <![CDATA[<?php
// Decide what errors to report:
error_reporting (E_ERROR | E_WARNING | E_NOTICE);
// Webmaster email and error page url:
$Wmemail = 'you@ursite.com';
$ErrorPage = 'http://www.ursite.com/error.html';
// This function will check the error type:
function MailErrorHandler($errno, $errstr, $errfile='?', $errline= '?')
{
global $Wmemail, $ErrorPage;
if (($errno & error_reporting()) == 0)
return;
$err = '';
switch($errno) {
case E_ERROR: $err = 'FATAL'; break;
case E_WARNING: $err = 'ERROR'; break;
case E_NOTICE: return;
}
// Send the error details via email:
mail($Wmemail,
"PHP: $errfile, $errline",
"$errfile, Line $errline\n$err($errno)\n$errstr");
// Redirect to the error page:
print '&lt;META HTTP-EQUIV="Refresh" CONTENT="0;url='.$ErrorPage.'">';
die();
}
set_error_handler('MailErrorHandler');
?>]]>
      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2007/11/php_2.html</feedburner:origLink></entry>
<entry>
   <title>MySQLi函数库</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/vNZFZGFczTQ/mysqli.html" />
   <id>tag:www.ruanyifeng.com,2007:/notes//4.973</id>
   
   <published>2007-11-14T04:16:15Z</published>
   <updated>2007-11-14T17:10:17Z</updated>
   
   <summary>1.

版本支持：</summary>
   <author>
      <name />
      
   </author>
         <category term="数据库" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      1.

版本支持：

PHP &gt; 5.0

MySQL &gt; 4.0

2.

连接数据库：

$db = new mysqli(host,database,user,password);

这是对象导向的连接方法，还有一种过程导向的连接方法。前者返回一个对象，后者返回一个资源。

$db = mysqli_connect(host,database,user,password);

3.

连接出错函数：

mysqli_connect_error();

如果连接出错，该函数返回一个错误号，否则返回0；

4.

选择数据库：

$db-&gt;select_db(dbname);

or

mysqli_select_db(db_resource,db_name);

5.

执行查询

$result = $db-&gt;query($query);

or

$result = mysqli_query($db,$query);

6.

返回结果的行数：

$num_results = $result-&gt;num_rows;

or

$num_results = mysqli_num_rows($result);

7.

取出每一行的结果（返回关系型数组）：

$row = $result-&gt;fetch_assoc();

or

$row = mysqli_fetch_assoc($result);

8.

取出每一行的结果（返回计数型数组）：

$row = $result-&gt;fetch_row($result);

or

$row = mysqli_fetch_row($result);

9.

取出每一行的结果（返回一个对象）：

$row = $result-&gt;fetch_object();

or

$row = mysqli_fetch_object($result);

10.

释放查询结果：

$result-&gt;free();

or

mysqli_free_result($result);

11.

关闭数据库连接：

$db-&gt;close();

or

mysqli_close($db);

12.

一条查询所影响的行数：

$db-&gt;affected_rows;

or

mysqli_affected_rows($result);

13.

模式化SQL语句执行：

$query = “insert into books values(?, ?, ?, ?)”;
$stmt = $db-&gt;prepare($query);
$stmt-&gt;bind_param(“sssd”, $isbn, $author, $title, $price);
$stmt-&gt;execute();
echo $stmt-&gt;affected_rows.’ book inserted into database.’;
$stmt-&gt;close();

在过程化执行方式中，

$db-&gt;prepare()对应mysqli_stmt_prepare()函数；
$stmt-&gt;bind_param()对应mysqli_stmt_bind_param()函数；
$stmt-&gt;execute() 对应mysqli_stmt_execute()函数；


      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2007/11/mysqli.html</feedburner:origLink></entry>
<entry>
   <title>MySQL中的子查询（subqueries）</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/4TSdwL4waNg/mysqlsubqueries.html" />
   <id>tag:www.ruanyifeng.com,2007:/notes//4.972</id>
   
   <published>2007-11-13T06:31:38Z</published>
   <updated>2007-11-13T15:04:56Z</updated>
   
   <summary>1. 

示例：</summary>
   <author>
      <name />
      
   </author>
         <category term="数据库" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      1. 

示例：

select customerid, amount
from orders
where amount = (select max(amount) from orders);

2.

子查询中使用的操作符：

* ANY

SELECT c1 FROM t1 WHERE c1 &gt; ANY (SELECT c1 FROM t2);

Returns true if the comparison is true for any of the rows in the subquery.

*  IN

SELECT c1 FROM t1
WHERE c1 IN
(SELECT c1 from t2);

* SOME

SELECT c1 FROM t1
WHERE c1 &gt;
SOME (SELECT c1 FROM t2);!

* ALL

SELECT c1 FROM t1
WHERE c1 &gt;
ALL (SELECT c1 from t2);

3.

exists 操作符

select isbn, title
from books
where not exists
(select * from order_items where order_items.isbn=books.isbn);

4.

行匹配

select c1, c2, c3
from t1
where (c1, c2, c3) in (select c1, c2, c3 from t2);

5.

用子查询生成一个暂时性表格

select * from
(select customerid, name from customers where city=Box Hill)
as box_hill_customers;

注意，子查询后面的as从句是必须的。

      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2007/11/mysqlsubqueries.html</feedburner:origLink></entry>
<entry>
   <title>MySQL 笔记（III）</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/p_UCM6N1Xv8/mysql_iii.html" />
   <id>tag:www.ruanyifeng.com,2007:/notes//4.971</id>
   
   <published>2007-11-12T10:46:09Z</published>
   <updated>2007-11-12T19:19:43Z</updated>
   
   <summary>MySQl的数据类型。</summary>
   <author>
      <name />
      
   </author>
         <category term="数据库" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      MySQl的数据类型。

16.

整数类型：TINYINT、SMALLINT、MEDIUMINT、INT、BIGINT。

17.

浮点数类型：FLOAT、DOUBLE、DECIMAL。

18.

日期和时间类型：DATE、TIME、DATETIME、TIMESTAMP、YEAR。

19.

字符串数据类型：

[NATIONAL] CHAR(M) [BINARY|ASCII|UNICODE]

[NATIONAL] VARCHAR(M) [BINARY]

TINYBLOB

TINYTEXT

BLOB

TEXT

MEDIUMBLOB

MEDIUMTEXT

LONGBLOB

LONGTEXT

ENUM('value1','value2','value3'...)  最大65535项

SET（'value1','value2',...） 最大64项
      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2007/11/mysql_iii.html</feedburner:origLink></entry>
<entry>
   <title>MySQL 笔记（II）</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/wpJwJ4jHxSU/mysql_ii.html" />
   <id>tag:www.ruanyifeng.com,2007:/notes//4.970</id>
   
   <published>2007-11-11T12:34:01Z</published>
   <updated>2007-11-12T15:45:15Z</updated>
   
   <summary>10.

GRANT命令用于授予用户权力，REVOKE命令用于除去用户的权力。</summary>
   <author>
      <name />
      
   </author>
         <category term="数据库" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      10.

GRANT命令用于授予用户权力，REVOKE命令用于除去用户的权力。

MySQL权力分为四级：Global、Database、Table和Column。

11.

GRANT语句格式：

GRANT privileges [columns]

ON item

TO user_name [IDENTIFIED BY 'password']

[REQUIRE ssl_option]

[WITH [GRANT OPTION| limit_options]]

示例：

grant all
on *
to fred identified by 'mnb123'
with grant option;

12.

MySQL的系统数据库：mysql.user, mysql.db, mysql.host, mysql.tables_priv, mysql.columns_priv。

13.

REVOKE 语句的格式：

REVOKE privileges [(columns)]
on item
FROM user_name

or

REVOKE ALL PRIVILEGES, GRANT
FROM user_name

14.

创建并授权一个典型的PHP用户：

grant select, insert, delete, update
on books.*
to bookorama identified by 'bookorama123';

15.

新建索引：

CREATE [UNIQUE|FULLTEXT] INDEX index_name
ON table_name (index_column_name[(length)] [ASC | DESC],...])

lenght 表示对字段前面多长的字符进行索引。

ASC和DESC表示索引的排序顺序，缺省是ASC。
      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2007/11/mysql_ii.html</feedburner:origLink></entry>
<entry>
   <title>MySQL 笔记（I）</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/FsklBGTLB48/mysql_i.html" />
   <id>tag:www.ruanyifeng.com,2007:/notes//4.969</id>
   
   <published>2007-11-04T13:11:04Z</published>
   <updated>2007-11-11T20:33:02Z</updated>
   
   <summary>1.

null值不能与任何其他值比较，包括自身。这样比较的话，只能返回null。</summary>
   <author>
      <name />
      
   </author>
         <category term="数据库" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      <![CDATA[1.

null值不能与任何其他值比较，包括自身。这样比较的话，只能返回null。

测试是否null，可以使用IS NULL和IS NOT NULL。

null的专用比较符是“<=>”，它会返回True/False。

2.

默认的排序顺序是升序。

升序时，Null值在最前，降序时，Null值在最后。

3.

随机抽取一个记录

order by RAND() LIMIT 1

4.

将两列数据合并在一起

concat()函数

5. MySQL的日期函数

NOW()
YEAR()
MONTH()
MONTHNAME()
DAYOFMONTH()
CURRENR_DATE 常量
TO_DAYS() 计算天数
DATE_ADD() 从一个日期计算另一个日期
DATE_SUB() 同上

6. 模式匹配

运算符：LIKE和NOT LIKE（不区分大小写）
“_” 匹配单个字符
“%” 匹配任意字符序列

7. 生成汇总

DISTINCT 只输出单一值
COUNT(*) 给出查询的行数
COUNT(col_name) 只对非null值进行计数
COUNT(DISTINCT col_name) 

8. 表的左联操作

from table_name1 LEFT JOIN table_name2 on condition

9. 修改表结构

ALTER TABLE table_name ADD column_name column_definition
]]>
      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2007/11/mysql_i.html</feedburner:origLink></entry>
<entry>
   <title>如何销毁一个session？</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/u0b2hO67Po8/session.html" />
   <id>tag:www.ruanyifeng.com,2007:/notes//4.968</id>
   
   <published>2007-11-02T17:23:22Z</published>
   <updated>2007-11-03T01:30:26Z</updated>
   
   <summary>第一步，销毁session存在服务器端的数据。 session_destroy(); 第二步，删除客户端的session cookie setcookie(session_name(),'',time()-3600); 第三步，销毁全局变量$_SESSION $_SESSION=array();...</summary>
   <author>
      <name />
      
   </author>
         <category term="PHP" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      第一步，销毁session存在服务器端的数据。

session_destroy();

第二步，删除客户端的session cookie

setcookie(session_name(),'',time()-3600);

第三步，销毁全局变量$_SESSION

$_SESSION=array();
      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2007/11/session.html</feedburner:origLink></entry>
<entry>
   <title>PHP的错误处理</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/ndL1solOOwc/php_1.html" />
   <id>tag:www.ruanyifeng.com,2007:/notes//4.967</id>
   
   <published>2007-10-31T12:08:22Z</published>
   <updated>2007-10-31T23:21:11Z</updated>
   
   <summary><![CDATA[1. 错误报告 error_reporting(E_ALL & ~E_NOTICE) 2. 手工抛出一个错误 trigger_error(message,[error_type]); 可选参数error_type必须是E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE中的一个。 3. 指定错误处理函数 set_error_handle(callback_function,[int error_type]) 选填的error_type用来指定所要处理的错误类型。 [错误处理函数的范例] function my_error_handle($in_errno,$in_errstr,$in_errfile,$in_errline,$in_errcontext) { { $errs = array( 2 => 'E_WARNING', 8 => 'E_NOTICE', 256 => 'E_USER_ERROR', 512 => 'E_USER_WARNING', 1024 => 'E_USER_NOTICE', );...]]></summary>
   <author>
      <name />
      
   </author>
         <category term="PHP" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      <![CDATA[1. 错误报告

error_reporting(E_ALL & ~E_NOTICE)

2. 手工抛出一个错误

trigger_error(message,[error_type]);

可选参数error_type必须是E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE中的一个。

3. 指定错误处理函数

set_error_handle(callback_function,[int error_type])

选填的error_type用来指定所要处理的错误类型。

[错误处理函数的范例]

function my_error_handle($in_errno,$in_errstr,$in_errfile,$in_errline,$in_errcontext)
{
{
  $errs = array(
    2 => 'E_WARNING',
    8 => 'E_NOTICE',
    256 => 'E_USER_ERROR',
    512 => 'E_USER_WARNING',
    1024 => 'E_USER_NOTICE',
  );

  $err_type = '';
  foreach ($errs as $val => $errstr)
  {
    if (($in_errno & $val) != 0)
    {
      $err_type .= "$errstr ";
    }
  }

  echo <<<EOTABLE

  <table align='center' width='75%' border='1' bgcolor='red'>
  <tr>
    <td valign='center' align='center'>
      <img src='kaboom.png' border='0'/>
    </td>
    <td>
      <b> We're sorry, but an error has occurred.</b><br/>
      <b>$err_type:</b>($in_errfile, line $in_errline)<br/>
      $in_errstr<br/>
    </td>
  </tr>
  </table>

EOTABLE;

  // exit on errors, continue otherwise.
  if ($in_errno == E_USER_ERROR)
    exit;
}


}

调用范例：

set_error_handler('my_error_handler');

4. 调用错误日志函数

error_log(message,delivery_type,destination,email_headers);

第二个参数0表示写入系统日志，1表示发送Email，3表示写入用户指定的文件。

[范例]

error_log($error_message,3,'../logs/auth.log');
header('Location:/login.php?err=1');
exit;

5. 打开错误显示

ini_set(‘display_errors’，‘on’);

6. 抛出一个例外

throw new Exception('Day value must be between 0 and 6');

7. 捕捉一个例外

try
{
  $day = get_day_of_week($dayvalue);
}
catch (Exception $e)
{
  echo 'An exception was thrown: ' . $e->getMessage();
}

]]>
      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2007/10/php_1.html</feedburner:origLink></entry>
<entry>
   <title>十步解决php utf-8编码（转贴）</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/FMffbou05F0/php_utf8.html" />
   <id>tag:www.ruanyifeng.com,2007:/notes//4.966</id>
   
   <published>2007-10-29T05:22:57Z</published>
   <updated>2007-10-29T13:33:07Z</updated>
   
   <summary>php用UTF-8总结：</summary>
   <author>
      <name />
      
   </author>
         <category term="PHP" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      php用UTF-8总结：

1、php文件本身必须是UTF-8编码。不像Java会生成class文件，避免这个问题

2、php要输出头：header(”Content-Type: text/html; charset=UTF-8″)

3、meta标签无所谓，有header所有浏览器就会按header来解析

4、所有外围都得用UTF8，包括数据库、*.js、*.css(CSS影响倒不大)

5、php本身不是Unicode的，所有substr之类的函数得改成mb_substr（需要装mbstring扩展）；或者用iconv转码（基本上的linux都装了，没装的话download、tar、make、make install，很简单的）

6、my.ini:
[mysql]
default-character-set=utf8
[mysqld]
default-character-set=utf8
default-storage-engine=MyISAM
在[mysqld]下加入:
default-collation=utf8_bin
init_connect='SET NAMES utf8'

7、在需要做数据库操作的php程序前面加上
mb_internal_encoding('utf-8');

8、create table最后边加上ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin

9、phpMyAdmin/config.inc.php
$cfg['DefaultCharset'] = 'utf-8';
$cfg['RecodingEngine'] = 'iconv';

10、phpAdmin导出数据时
把"二进制区域使用十六进制显示"的勾去掉

特别郁闷的：文件系统函数不支持UTF-8！

听说php6已经内置Unicode支持，以后试一下
      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2007/10/php_utf8.html</feedburner:origLink></entry>
<entry>
   <title>在线编辑器实现原理(兼容IE和FireFox)（转）</title>
   <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ruanyifeng_it/~3/1eWLXBaq8ig/iefirefox.html" />
   <id>tag:www.ruanyifeng.com,2007:/notes//4.964</id>
   
   <published>2007-10-23T09:45:43Z</published>
   <updated>2007-10-23T17:51:59Z</updated>
   
   <summary>在线编辑器在我们日常的项目开发中非常有用（如新闻系统），它可以方便地实现文章的在线编辑，省掉了FrontPage等工具。那么是怎样实现浏览器在线编辑功能的呢?  首先需要IE的支持,在IE5.5以后就有一个编辑状态. 就是利用这个编辑状态,然后用javascript来控制在线编辑的。</summary>
   <author>
      <name />
      
   </author>
         <category term="Javascript" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="ja" xml:base="http://www.ruanyifeng.com/notes/">
      <![CDATA[在线编辑器在我们日常的项目开发中非常有用（如新闻系统），它可以方便地实现文章的在线编辑，省掉了FrontPage等工具。那么是怎样实现浏览器在线编辑功能的呢?  首先需要IE的支持,在IE5.5以后就有一个编辑状态. 就是利用这个编辑状态,然后用javascript来控制在线编辑的。

     首先要有一个编辑框，这个编辑框其实就是一个可编辑状态的网页， 我们用iframe来建立编辑框。
     &lt;IFRAME id=&iexcl;&deg;HtmlEdit&iexcl;&plusmn; style=&quot;WIDTH: 100%; HEIGHT: 296px&quot; marginWidth=&iexcl;&deg;0&iexcl;&plusmn; marginHeight=&iexcl;&deg;0&iexcl;&plusmn;&gt;&lt;/IFRAME&gt;

程序代码

程序代码</div><div class="UBBContent"><br>&nbsp;&nbsp;&lt;script language="javascript"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp; var editor;<br>&nbsp;&nbsp;&nbsp;&nbsp; editor = document.getElementById("HtmlEdit").contentWindow;<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; //只需键入以下设定，iframe立刻变成编辑器。<br>&nbsp;&nbsp;&nbsp;&nbsp; editor.document.designMode = 'On';<br>&nbsp;&nbsp;&nbsp;&nbsp; editor.document.contentEditable = true;<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; //但是IE与FireFox有点不同，为了兼容FireFox，所以必须创建一个新的document。<br>&nbsp;&nbsp;&nbsp;&nbsp; editor.document.open();<br>&nbsp;&nbsp;&nbsp;&nbsp; editor.document.writeln('&lt;html&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;');<br>&nbsp;&nbsp;&nbsp;&nbsp; editor.document.close();<br><br>&nbsp;&nbsp;&nbsp;&nbsp; //字体特效 － 加粗方法一 <br>&nbsp;&nbsp;&nbsp;&nbsp; function addBold()<br>&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp; editor.focus();<br>&nbsp;&nbsp;&nbsp;&nbsp; //所有字体特效只是使用execComman()就能完成。<br>&nbsp;&nbsp;&nbsp;&nbsp; editor.document.execCommand("Bold", false, null);<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp; //字体特效 － 加粗方法二 <br>&nbsp;&nbsp;&nbsp;&nbsp; function addBold()<br>&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp; editor.focus();<br>&nbsp;&nbsp;&nbsp;&nbsp; //获得选取的焦点<br>&nbsp;&nbsp;&nbsp;&nbsp; var sel = editor.document.selection.createRange();<br>&nbsp;&nbsp;&nbsp;&nbsp; insertHTML("&lt;b&gt;"+sel.text+"&lt;/b&gt;");<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp; function insertHTML(html)<br>&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (editor.document.selection.type.toLowerCase() != "none")<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; editor.document.selection.clear() ;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; editor.document.selection.createRange().pasteHTML(html) ; <br>&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&lt;/script&gt;<br></div>]]>
      
   </content>
<feedburner:origLink>http://www.ruanyifeng.com/notes/2007/10/iefirefox.html</feedburner:origLink></entry>

</feed>

