php实现替换UTF
批量去除BOM的程序
function
replace_utf8bom(
$str
)
{
$charset
[1] =
substr
(
$str
,0,1);
$charset
[2] =
substr
(
$str
,1,1);
$charset
[3] =
substr
(
$str
,2,1);
if
(ord(
$charset
[1]) == 239 && ord(
$charset
[2]) == 187 && ord(
$charset
[3]) == 191)
{
return
substr
(
$str
,3);
}
else
{
return
false;
}
}
很明显,这就是前面三个字符是固定的原因,当然可以这样判断了。。。说白了很简单,但如果不知道就真的很痛苦了。顺便说一下,它来自:http://www.phptext.net/technology.php?vid=53
相关文档:
PHP Security for Deployers
If you're a Developer
READ THIS and then work with your SysAdmins to step through any and all the layers of security designed to protect your apps.
Example:
Traffic must first pass through a SPI firewall (ensure that ONLY necessary ports/protocols are permitted; en ......
<?
$_mysqlhost="localhost";
$_mysqluser="root";
$_mysqlpass="";
$_mysqldata="mydata";
$_connect=mysql_connect($_mysqlhost,$_mysqluser,$_mysqlpass) or die ("错误".mysql_error());
mysql_query("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary", $ ......
假如有两个表: user 和 articles 表
结构:
user: (id, name)
articles: (id,user_id,title,content)
其中user.id 和 user_id 关联
在user的 model中的 relations方法里面加:
return array('articles'=>array(self::HAS_MANY,'articles','user_id'));
在articles的 model中的 relations方法里面加:
......
引用文件的方法有2种:
1、require
require("conn.php"); 一般放在页面的第一行,做为该页执行的一部分,首先执行require内的conn.php 然后再执行下面的代码
2、include
include("header.php");当程序到达这里的时候才会执行include的 header.php ......