PHP截取固定长度字符串函数
<?php
function toFixLen($str,$len){ //固定长度字符串的截取
if($len>=strlen($str)||!$len) return $str;
$len-=3;
$tempstr1 = substr($str,0,$len); //截取字符串
$tempstr2 = preg_replace('/([\x81-\xff]+)$/ms','',$tempstr1,1); //去掉结尾的连续汉字字符
if(!is_int((strlen($tempstr1)-strlen($tempstr2))/2)){ //去掉的字符为奇数?
$tempstr1 = substr($str,0,$len-1);
}
return $tempstr1."…";
}
?>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/renren000/archive/2009/02/02/3858694.aspx
相关文档:
项目需要用到 新闻内容页 实现分页功能,随便写了一下。
给大家做个参考,写的不好还望谅解啊!
//新闻内容分页开始 The page next for news content start
$nextpage="<!--{nextpage}-->";//分页标示.
$content=explode($nextpage,$content);
$sum=count($content);
$mpurl=$_SERVER['PHP_SELF']."?newsid ......
<?php
/*
抛个砖,具体要做成什么样自己做。
*/
if(isset($_FILES['userfile']['tmp_name'])){
$userfile = $_FILES['userfile']['tmp_name']; //保存在系统的临时位置
$userfile_name = $_FILES['userfile']['name'];//文件名
$userfile_size = $_FILES['userfile'][ ......
1,类的结构声明方式:
class 类名 {
//类体
}
2,属性和方法的定义;
使用构造函数:
使用析构函数:
类的实例化:
3,控制访问权限:public , private protected;
4 ......
2200的路过。。PHP本身是简单,但学PHP不是指你走PHP这条路,而是指你走WEB这条路,会PHP,还要会ECSHOP,DZ,PHPCMS,帝国CMS各大程序,你会了么?好,你说你PHP很好,这些我都会,那AJAX?可以灵活运用?AJAX也会,那好,FLEX你会了么?都会,好,你可以自行在WIN2003或者LINUX下配置PHP环境,获取最优环境了么?若想高工资, ......
<?php
function remove_directory($dir) {
if ($handle = opendir("$dir")) {
while (false !== ($item = readdir($handle))) {
if ($item != "." && $item != "..") {
......