//输出一段utf-8编码的html
$this->show('欢迎使用 ThinkPHP!
','utf-8');
字符串替换$br=str_replace("/>", "/>
", $con);
php把文本框回车转换成html换行
$aa=@ereg_replace("rn"," ",$_POST['words']);//php把文本框回车转换成html换行
$bb=explode(' ',$aa);//字符串转为数组
$words=array_unique($bb);//数组去重复
$words=implode(' ',$words);//数组转为字符串
$data['dic'] =$words;
//file_put_contents — 将一个字符串写入文件 日志
/*
$file 文件名
$person 写入的内容
FILE_APPEND 如果文件
$file
已经存在,追加数据而不是覆盖。
*/
file_put_contents('log.log', $person, FILE_APPEND );
//正则替换中文文字
$string = "中文123高深abc开心。?我们";
echo preg_replace('#(?:(?![,。?])[xC0-xFF][x80-xBF]+)+#','$0',$string);
//中文123高深abc开心。?我们
//正则替换数字
echo preg_replace('#(d)+#','$0',$string);
//中文123高深abc开心。?我们
//(?:[xC0-xFF][x80-xBF]+) 单个中文字符,不需要引用,因此使用?:
//(?![,。?]) 排除中文标点符号,这里要写入中文标点
//(?:(?![,。?])[xC0-xFF][x80-xBF]+) 排除中文标点符号后的中文字符
//(?:[xC0-xFF][x80-xBF]+)+ 1个以上的中文字符
//去掉style行内样式
$str='';
echo preg_replace('/style=".*?"/',' ',$str);
html代码过滤并截取:$ser[$i]['description']= $this->CHsubstr(strip_tags($ser[$i]['description']),0,200);
字符串长度:strlen($string);
数字满三位添加一逗号:$proe[$i]['s_money']= number_format($proe[$i]['s_money']);
去掉重复(不统计):
$shopquan=M("quan")->group("s_id")->limit(0,6)->order("x_date desc")->select();
去掉重复(统计):
$count=M("Record")->where("uid=".$_SESSION['uid'])->count('distinct pid');
去掉重复
M("Article")->where("catid=12 and quyu !='".NULL."' and quyu!=''")->field("quyu")->distinct(true)->select();
截取字符串:mb_substr(字符串,开始,长度,utf8/gb2312);
查找单词初始位置:
strstr//搜索字符串在另一字符串中的首次出现从匹配点返回字符串的其余部分(对大小写敏感)未找到则返回 false
stristr("Hello world!","world");//查找字符串在另一字符串中第一次出现的位置(大小写不敏感)
//返回字符串在另一字符串中首次出现的位置(对大小写敏感)//如未找到则返回 false
strpos //返回字符串在另一字符串中第一次出现的位置(大小写不敏感)
stripos //返回字符串在另一字符串中第一次出现的位置(大小写不敏感)
获取文件后缀名:pathinfo($picurl, PATHINFO_EXTENSION)
error_reporting(0);//禁止显示PHP警告提示
define("PI",3.14);//定义常量
defined($string)//函数可以帮助我们判断一个常量是否已经定义
constant()//动态的输出不同的常量
//PHP自定函数截取字符串
$waihui_val = M("article")->where("catid=3")->order("inputtime desc")->limit("0,10")->select();
for($i=0;$i
$waihui_val[$i]['title']= $this->CHsubstr($waihui_val[$i]['title'],0,44);
}
$this->assign("waihui_val",$waihui_val);//dump($waihui_val);
//截取中文字符无乱码函数
function CHsubstr($string, $start, $length){
if(strlen($string)>$length){
$str='';
$len=$start+$length;
$i = $start;
while($i
if(ord(substr($string, $i, 1))>=128){
$str.=substr($string, $i, 3);
$i = $i+ 3;
}else{
$str.=substr($string, $i, 1);
$i ++;
}
}
$string=$str."...";
return $string;
}else{
return $string;
}
}
//加密会员登录的密码:
/**
* 加密会员登录的密码。
* @param int $username 账号
* @param string $password 登陆密码
* @return string 加密后的密码
* @see login, password
*/
function crypt($username, $password) {
$md5 = pack('H*', md5($username . '@' . $password . '.Z'));
return preg_replace('/=+$/', '', base64_encode($md5));
}
//处理传值为空
$id=!empty($_GET['id'])?$_GET['id']:147;
//传id,参数
{:U('Home/Decoration/info',array('id'=>$val['id']))}
//匹配关键字
html:
js:
$(document).ready(function (){
$("#sub_mit").click(function (){
var keyword = $("#keyword").val();
window.location.href="/links.html?l=SmVSUzJwdyswSzNXRnhjdEg5TU9XbjVVejJ5M003SmVqVU9YaVhjQkMwQW9aOEJuWUQvdlNVaXdsWVZ2dVhtWg%3D%3D"+keyword;
});
});
php:
$keyword = trim($_GET['keyword']);//I('post.keyword');
if (!empty($keyword)) {
$sql_sql="select * from `news` where `keywords` like '%{$keyword}%' order by date desc";
$this->assign("keyword",$keyword);
}