代码片段

来源:互联网 发布:东方梦华录mac 编辑:程序博客网 时间:2024/05/17 03:10

 

-html  表格换行的功能:

换行功能style="table-layout: fixed;WORD-BREAK: break-all; WORD-WRAP: break-word"

 

-php  php过滤危险html代码

非常感谢原文作者

原文地址:http://webservices.ctocio.com.cn/tips/52/7663552.shtml

 

function uh($str)
{
$farr = array(
"//s /", //过滤多余的空白
"/<(//?)(script|i?frame|style|html|body|title|link|meta|/?|/%)([^>]*?)>/isU", //过滤 <script 等可能引入恶意内容或恶意改变显示布局的代码,假如不需要插入flash等,还可以加入<object的过滤
"/(<[^>]*)on[a-zA-Z] /s*=([^>]*>)/isU", //过滤javascript的on事件

);
$tarr = array(
" ",
"<//1//2//3>", //假如要直接清除不安全的标签,这里可以留空
"//1//2",
);

$str = preg_replace( $farr,$tarr,$str);
return $str;
}

 

 

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

那么如何在PHP5中使用呢?PHP5中有2种连接sqlite的方法。一种是默认提供的,另一种是PDO类。默认的只支持sqlite2,但是PDO可以间接支持sqlite3。下面是我写的简单的PDO类可以兼容2个版本。

 

以下为引用的内容:

  1. class SQLite{ 
  2.     function __construct($file){ 
  3.         try{ 
  4.             $this->Connection=new PDO('sqlite2:'.$file); 
  5.         }catch(PDOException $e){ 
  6.             try{ 
  7.                 $this->Connection=new PDO('sqlite:'.$file); 
  8.             }catch(PDOException $e){ 
  9.                 exit('error!'); 
  10.             } 
  11.         } 
  12.     } 
  13.     function __destruct(){ 
  14.         $this->Connection=null; 
  15.     } 
  16.     function Query($SQL){ 
  17.         return $this->Connection->Query($SQL); 
  18.     } 
  19.     function Execute($SQL){ 
  20.         return $this->Query($SQL)->fetch(); 
  21.     } 
  22.     function RecordArray($SQL){ 
  23.         return $this->Query($SQL)->fetchAll(); 
  24.     } 
  25.     function RecordCount($SQL){ 
  26.         return count($this->RecordArray($SQL)); 
  27.     } 
  28.     function RecordLastID(){ 
  29.         return $this->Connection->lastInsertId(); 
  30.     } 

然后实例化,在实例化中如果数据库存在就自动打开,不存在就会自动创建数据库

 

以下为引用的内容:

$DB=new SQLite('blog.db');  //这个数据库文件名字任意

创建数据库表

 

以下为引用的内容:

$DB->Query("create table test(id integer primary key,title varchar(50)"); 

接下来添加数据

 

以下为引用的内容:

  1. $DB->Query("insert into test(title) values('泡菜')");   
  2. $DB->Query("insert into test(title) values('蓝雨')");   
  3. $DB->Query("insert into test(title) values('Ajan')");   
  4. $DB->Query("insert into test(title) values('傲雪蓝天')");  

之后就是如何读取数据了。也就是循环。

 

以下为引用的内容:

  1. $SQL='select title from test order by id desc';   
  2. foreach($DB->Query($SQL) as $RS){   
  3.     echo $RS['title'];   
  4. }   

对于企业来说SQLITE可能会小点,但是对于个人来说它确实是个好东西,可移植性非常好。

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

原创粉丝点击