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 ......
引用http://www.linuxtone.org/html/76/t-2776.html
有时候nginx,apache,mysql,php编译完了想看看编译参数可以用以下方法
nginx编译参数:
#/usr/local/nginx/sbin/nginx -V
CODE:
nginx version: nginx/0.6.32
built by gcc 4.1.2 20071124 (Red Hat 4.1.2-42)
configure arguments: --user=www --group=www --p ......
<?php
function remove_directory($dir) {
if ($handle = opendir("$dir")) {
while (false !== ($item = readdir($handle))) {
if ($item != "." && $item != "..") {
......
PHP是一门开发速度快,运行速度快的语言,但是它也有致命缺点,无多线程(虽然Apache的服务器在另一种程度上弥补了这种缺陷,但是在编写一些需要高并发并且考虑效率的程序下,它还是明显不足)。
但是PHP可以大大缩短开发周期,与开发成本(比如PHP对于程序要求的门槛很低)。
总体来说,PHP很适合开发网站来用,而在开发 ......